using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Diagnostics;
using System.Runtime.InteropServices;
using AeroNonClientButtons;
using System.Threading;
using Utility;
using System.Globalization;
using Microsoft.VisualBasic;
using System.Windows.Forms.DataVisualization.Charting;
using System.Drawing.Design;
using System.Windows.Forms.Design;

namespace MKDS_Course_Editor
{
    public partial class nkm : Form
    {
        public static object item = null;
        string KTPM = "";
        string KTPC = "";
        string path_ = "";
        string EPOI = "";
        byte[] stag;
        public nkm(string path)
        {
            path_ = path;
            InitializeComponent();
        }
        public string DecToHex(double DecNum)
        {
            double remainder = 0;
            string HexStr = null;
            HexStr = "";
            while (DecNum != 0)
            {
                remainder = DecNum % 16;
                if (remainder <= 9)
                {
                    HexStr = Strings.Chr(Strings.Asc(remainder.ToString())) + HexStr;
                }
                else
                {
                    HexStr = Strings.Chr(Strings.Asc("A") + (int)remainder - 10) + HexStr;
                }
                DecNum = DecNum / 16;
            }
            if (string.IsNullOrEmpty(HexStr))
                HexStr = "0";
            return HexStr;
        }
        public string HexConverter(double ValueRead)
        {
            
            double NumDecimal = 0;
            string ByteA = null;
            string ByteB = null;
            string ByteC = null;
            string ByteD = null;
            string ByteComplete = null;
            bool Positivo = false;
            bool Grande = false;


            NumDecimal = ValueRead;
            if (NumDecimal < 0)
                Positivo = false;
            else
                Positivo = true;
            NumDecimal = Math.Abs(NumDecimal);
            Grande = false;
            if (NumDecimal >= 4096)
            {
                Grande = true;
                NumDecimal = NumDecimal - 4096;
            }
            NumDecimal = NumDecimal * 4096;
            if (Positivo == false)
                NumDecimal = 16777216 - NumDecimal;

            //ByteComplete = DecToHex(NumDecimal);
            ByteComplete = Conversion.Hex(NumDecimal);

            if (Strings.Len(ByteComplete) == 1)
                ByteComplete = "00000" + ByteComplete;
            if (Strings.Len(ByteComplete) == 2)
                ByteComplete = "0000" + ByteComplete;
            if (Strings.Len(ByteComplete) == 3)
                ByteComplete = "000" + ByteComplete;
            if (Strings.Len(ByteComplete) == 4)
                ByteComplete = "00" + ByteComplete;
            if (Strings.Len(ByteComplete) == 5)
                ByteComplete = "0" + ByteComplete;

            ByteA = Strings.Mid(ByteComplete, 5, 2);
            ByteB = Strings.Mid(ByteComplete, 3, 2);
            ByteC = Strings.Mid(ByteComplete, 1, 2);

            if (Positivo == true)
            {
                if (Grande == true)
                    ByteD = "01";
                else
                    ByteD = "00";
            }
            else
            {
                if (Grande == true)
                    ByteD = "FE";
                else
                    ByteD = "FF";
            }

            return "" + (ByteA) + (ByteB) + (ByteC) + (ByteD);

        }
        private void nkm_Load(object sender, EventArgs e)
        {

            //load();
            Read();

        }
        /*public void load()
        {
            Directory.CreateDirectory("img\\tmp");
            nkm_file.nkm nkm = new nkm_file.nkm();
            BinaryReader br = new BinaryReader(File.OpenRead(path_));



            nkm.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
            if (nkm.id == "NKMD")
            {
                br.ReadBytes(2);
                nkm.HEADER.start = System.BitConverter.ToString(br.ReadBytes(1));
                br.ReadBytes(5);
                nkm.HEADER.PATH = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.POIT = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.STAG = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.KTPS = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.KTPJ = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.KTP2 = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                switch (nkm.HEADER.start)
                {
                    case "44":
                        break;
                    case "48":
                        nkm.HEADER.KTPC = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        break;
                    case "4C":
                        nkm.HEADER.KTPC = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        nkm.HEADER.KTPM = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        break;
                }
                nkm.HEADER.CPOI = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.CPAT = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.IPOI = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.IPAT = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.EPOI = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.EPAT = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.AREA = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.HEADER.CAME = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                nkm.OBJI.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.OBJI.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                for (int i = 0; i < nkm.OBJI.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    //byte[] b = br.ReadBytes(4);
                    //decimal one = parselittle2(new byte[] { b[3], b[2], b[1], b[0] });
                    n.SubItems.Add(one.ToString());
                    float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(two.ToString());
                    float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(three.ToString());
                    float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(four.ToString());
                    float five = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(five.ToString());
                    float six = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(six.ToString());
                    float seven = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(seven.ToString());
                    float eight = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(eight.ToString());
                    float nine = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(nine.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView1.Items.Add(n);

                    chart1.Series[0].Points.AddXY(one, three);
                    chart1.Series[0].Points[i].Color = Color.Transparent;

                    switch (n.SubItems[10].Text.Remove(4))
                    {
                        case "6500":
                            chart1.Series[0].Points[i].MarkerImage = "img\\box.png";
                            break;
                        case "6800":
                            chart1.Series[0].Points[i].MarkerImage = "img\\coin.png";
                            break;
                        case "6B00":
                            chart1.Series[0].Points[i].MarkerImage = "img\\star.png";
                            break;
                        case "C900":
                            chart1.Series[0].Points[i].MarkerImage = "img\\box.png";
                            break;
                        case "6E00":
                            chart1.Series[0].Points[i].MarkerImage = "img\\poort.png";
                            break;
                        case "5901":
                            Bitmap f = RotateImg(new Bitmap("img\\hek.png"), five, Color.Transparent);
                            f.Save("img\\tmp\\hek" + five + ".png");
                            chart1.Series[0].Points[i].MarkerImage = "img\\tmp\\hek" + five + ".png";
                            f.Dispose();
                            break;
                        case "9B01":
                            chart1.Series[0].Points[i].MarkerImage = "img\\fish.png";
                            break;
                        case "AC01":
                            chart1.Series[0].Points[i].MarkerImage = "img\\crab.png";
                            break;
                        case "A501":
                        case "9601":
                            chart1.Series[0].Points[i].MarkerImage = "img\\chain.png";
                            break;
                        case "9101":
                            chart1.Series[0].Points[i].MarkerImage = "img\\goomba.png";
                            break;
                        case "A601":
                            chart1.Series[0].Points[i].MarkerImage = "img\\plant.png";
                            break;
                        case "B001":
                            chart1.Series[0].Points[i].MarkerImage = "img\\bal.png";
                            break;
                        case "A901":
                            chart1.Series[0].Points[i].MarkerImage = "img\\flip.png";
                            break;
                        case "A801":
                            chart1.Series[0].Points[i].MarkerImage = "img\\bound.png";
                            break;
                        case "B301":
                            chart1.Series[0].Points[i].MarkerImage = "img\\bal.png";
                            break;
                        case "CE00":
                            chart1.Series[0].Points[i].MarkerImage = "img\\CE00.png";
                            break;
                        case "CD00":
                            chart1.Series[0].Points[i].MarkerImage = "img\\CD00.png";
                            break;
                        case "A401":
                        case "AF01":
                        case "9801":
                            chart1.Series[0].Points[i].MarkerImage = "img\\firebal.png";
                            break;
                        case "3801":
                        case "3F01":
                            chart1.Series[0].Points[i].MarkerImage = "img\\g_tree.png";
                            break;
                        case "A701":
                        case "9901":
                            chart1.Series[0].Points[i].MarkerImage = "img\\mole.png";
                            break;
                        case "6700":
                            chart1.Series[0].Points[i].MarkerImage = "img\\wood.png";
                            break;
                        case "3501":
                            chart1.Series[0].Points[i].MarkerImage = "img\\kill.png";
                            break;
                        case "3A01":
                            chart1.Series[0].Points[i].MarkerImage = "img\\c_tree.png";
                            break;
                        case "3E01":
                            chart1.Series[0].Points[i].MarkerImage = "img\\b_tree.png";
                            break;
                        case "4901":
                            chart1.Series[0].Points[i].MarkerImage = "img\\egg.png";
                            break;
                        case "2D01":
                        case "2E01":
                            chart1.Series[0].Points[i].MarkerImage = "img\\b_tree1.png";
                            break;
                        case "CF00":
                            chart1.Series[0].Points[i].MarkerImage = "img\\pendulum.png";
                            break;
                        case "6D00":
                            switch (n.SubItems[11].Text)
                            {
                                case "03000000":
                                    chart1.Series[0].Points[i].MarkerImage = "img\\mushroom.png";
                                    break;
                                case "02000000":
                                    chart1.Series[0].Points[i].MarkerImage = "img\\banaan.png";
                                    break;
                                default:
                                    chart1.Series[0].Points[i].MarkerColor = Color.Red;
                                    break;
                            }
                            break;
                        default:
                            if (File.Exists("img\\" + n.SubItems[10].Text.Remove(4) + ".png"))
                            {
                                chart1.Series[0].Points[i].MarkerImage = "img\\" + n.SubItems[10].Text.Remove(4) + ".png";
                            }
                            else
                            {
                                chart1.Series[0].Points[i].MarkerColor = Color.Red;
                            }
                            break;
                    }

                    chart1.Series[0].Points[i].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
                }
                nkm.PATH.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.PATH.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.PATH.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.PATH.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView2.Items.Add(n);
                }
                Color poitColor = Color.LemonChiffon;
                nkm.POIT.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.POIT.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.POIT.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.POIT.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(two.ToString());
                    float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(three.ToString());
                    float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(four.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    if (four == 0)
                    {
                        poitColor = poitColor == Color.White ? Color.LemonChiffon : Color.White;
                    }
                    n.BackColor = poitColor;
                    listView3.Items.Add(n);
                    chart1.Series[1].Points.AddXY(one, three);
                    chart1.Series[1].Points[i].Color = Color.Transparent;
                    chart1.Series[1].Points[i].MarkerColor = Color.DarkBlue;
                }
                nkm.STAG.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.STAG.length = nkm.HEADER.KTPS - nkm.HEADER.STAG - 4;
                if (nkm.STAG.length == 2)
                {
                    br.ReadBytes(2);
                }
                else
                {
                    ListViewItem n_ = new ListViewItem("0");
                    stag = br.ReadBytes(nkm.STAG.length);
                    int one_ = int.Parse(System.BitConverter.ToString(stag, 2, 1).Replace("-", ""), System.Globalization.NumberStyles.HexNumber);
                    n_.SubItems.Add(one_.ToString());
                    listView4.Items.Add(n_);
                }
                nkm.KTPS.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.KTPS.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.KTPS.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.KTPS.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(two.ToString());
                    float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(three.ToString());
                    float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(four.ToString());
                    float five = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(five.ToString());
                    float six = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(six.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView5.Items.Add(n);

                    chart1.Series[2].Points.AddXY(one, three);
                    chart1.Series[2].Points[i].Color = Color.Transparent;
                    Bitmap f = RotateImg(new Bitmap("img\\start.png"), five, Color.Transparent);
                    f.Save("img\\tmp\\start" + five + ".png");
                    chart1.Series[2].Points[i].MarkerImage = "img\\tmp\\start" + five + ".png";
                    f.Dispose();
                }
                if (nkm.KTPS.count * 28 != nkm.HEADER.KTPJ - nkm.HEADER.KTPS - 8)
                {
                    br.ReadBytes(nkm.HEADER.KTPJ - nkm.HEADER.KTPS - 8 - nkm.KTPS.count * 28);
                }
                nkm.KTPJ.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.KTPJ.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                bool ktp2_ = false;
                if (nkm.KTPJ.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.KTPJ.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(two.ToString());
                    float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(three.ToString());
                    float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(four.ToString());
                    float five = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(five.ToString());
                    float six = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(six.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    float eight = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    if (eight == 844125259)
                    {
                        ktp2_ = true;
                    }
                    else
                    {
                        n.SubItems.Add(eight.ToString());
                    }
                    listView6.Items.Add(n);

                    chart1.Series[3].Points.AddXY(one, three);
                    chart1.Series[3].Points[i].Color = Color.Transparent;
                    chart1.Series[3].Points[i].MarkerColor = Color.Orange;
                }
                // br.ReadBytes(nkm.HEADER.KTP2 - nkm.HEADER.KTPJ - 8 - nkm.KTPJ.count * 32);
                if (ktp2_ == true)
                {
                    nkm.KTP2.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    for (int i = 0; i < nkm.KTP2.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(one.ToString());
                        float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(two.ToString());
                        float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(three.ToString());
                        float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(four.ToString());
                        float five = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(five.ToString());
                        float six = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(six.ToString());
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        listView7.Items.Add(n);

                        chart1.Series[4].Points.AddXY(one, three);
                        chart1.Series[4].Points[i].Color = Color.Transparent;
                        chart1.Series[4].Points[i].MarkerColor = Color.LightSkyBlue;
                    }
                }
                else
                { nkm.KTP2.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString(); }
                nkm.KTP2.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                for (int i = 0; i < nkm.KTP2.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(two.ToString());
                    float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(three.ToString());
                    float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(four.ToString());
                    float five = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(five.ToString());
                    float six = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(six.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView7.Items.Add(n);

                    chart1.Series[4].Points.AddXY(one, three);
                    chart1.Series[4].Points[i].Color = Color.Transparent;
                    chart1.Series[4].Points[i].MarkerColor = Color.LightSkyBlue;
                }
                switch (nkm.HEADER.start)
                {
                    case "44":
                        if (nkm.KTP2.count * 28 != nkm.HEADER.CPOI - nkm.HEADER.KTP2 - 8)
                        {
                            br.ReadBytes(nkm.HEADER.CPOI - nkm.HEADER.KTP2 - 8 - nkm.KTP2.count * 28);
                        }
                        break;
                    case "48":
                    case "4C":
                        if (nkm.KTP2.count * 28 != nkm.HEADER.KTPC - nkm.HEADER.KTP2 - 8)
                        {
                            br.ReadBytes(nkm.HEADER.KTPC - nkm.HEADER.KTP2 - 8 - nkm.KTP2.count * 28);
                        }
                        break;
                }
                KTPC = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                if (KTPC == "KTPC")
                {
                    nkm.KTPC.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    for (int i = 0; i < nkm.KTPC.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(one.ToString());
                        float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(two.ToString());
                        float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(three.ToString());
                        float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(four.ToString());
                        float five = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(five.ToString());
                        float six = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(six.ToString());
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        listView8.Items.Add(n);

                        chart1.Series[5].Points.AddXY(one, three);
                        chart1.Series[5].Points[i].Color = Color.Transparent;
                        chart1.Series[5].Points[i].MarkerColor = Color.DeepPink;
                    }

                    KTPM = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                }
                else
                {
                    KTPM = KTPC;
                }

                if (KTPM == "KTPM")
                {
                    nkm.KTPM.id = KTPM;
                    nkm.KTPM.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    for (int i = 0; i < nkm.KTPM.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        listView9.Items.Add(n);
                    }
                    nkm.CPOI.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                }
                else
                {
                    nkm.CPOI.id = KTPM;
                }

                nkm.CPOI.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.CPOI.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.CPOI.count; i++)
                {
                    System.Windows.Forms.DataVisualization.Charting.DataPoint p = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0, 0);
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(two.ToString());
                    float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(three.ToString());
                    float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(four.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView10.Items.Add(n);
                    p.IsEmpty = true;
                    chart1.Series[6].Points.AddXY(one, two);
                    chart1.Series[6].Points.AddXY(three, four);
                    chart1.Series[6].Points.Add(p);
                }
                nkm.CPAT.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.CPAT.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.CPAT.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.CPAT.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView11.Items.Add(n);
                }
                nkm.IPOI.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.IPOI.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.IPOI.count == 0)
                {
                    br.ReadBytes(4);
                }
                if ((nkm.HEADER.IPAT - nkm.HEADER.IPOI) / 20 != nkm.IPOI.count)
                {
                    for (int i = 0; i < nkm.IPOI.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(one.ToString());
                        float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(two.ToString());
                        float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(three.ToString());
                        float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(four.ToString());
                        n.SubItems.Add("00000000");
                        listView12.Items.Add(n);

                        chart1.Series[7].Points.AddXY(one, three);
                        chart1.Series[7].Points[i].Color = Color.Transparent;
                        chart1.Series[7].Points[i].MarkerColor = Color.YellowGreen;
                    }
                }
                else
                {
                    for (int i = 0; i < nkm.IPOI.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(one.ToString());
                        float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(two.ToString());
                        float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(three.ToString());
                        float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(four.ToString());
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        listView12.Items.Add(n);

                        chart1.Series[7].Points.AddXY(one, three);
                        chart1.Series[7].Points[i].Color = Color.Transparent;
                        chart1.Series[7].Points[i].MarkerColor = Color.YellowGreen;
                    }
                }
                nkm.IPAT.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.IPAT.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.IPAT.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.IPAT.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView13.Items.Add(n);
                }
                nkm.EPOI.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.EPOI.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                EPOI = nkm.EPOI.id;
                if (nkm.EPOI.id == "EPOI")
                {
                    if (nkm.EPOI.count == 0)
                    {
                        br.ReadBytes(4);
                    }
                    for (int i = 0; i < nkm.EPOI.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(one.ToString());
                        float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(two.ToString());
                        float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(three.ToString());
                        float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(four.ToString());
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        listView14.Items.Add(n);

                        chart1.Series[8].Points.AddXY(one, three);
                        chart1.Series[8].Points[i].Color = Color.Transparent;
                        chart1.Series[8].Points[i].MarkerColor = Color.Gold;
                    }
                    nkm.EPAT.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                    nkm.EPAT.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    if (nkm.EPAT.count == 0)
                    {
                        br.ReadBytes(4);
                    }
                    for (int i = 0; i < nkm.EPAT.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(one.ToString());
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        listView15.Items.Add(n);
                    }
                }
                else
                {
                    if (nkm.EPOI.count == 0)
                    {
                        br.ReadBytes(4);
                    }
                    for (int i = 0; i < nkm.EPOI.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(one.ToString());
                        float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(two.ToString());
                        float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(three.ToString());
                        float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(four.ToString());
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        listView16.Items.Add(n);

                        chart1.Series[8].Points.AddXY(one, three);
                        chart1.Series[8].Points[i].Color = Color.Transparent;
                        chart1.Series[8].Points[i].MarkerColor = Color.Gold;
                    }
                    nkm.EPAT.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                    nkm.EPAT.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    if (nkm.EPAT.count == 0)
                    {
                        br.ReadBytes(4);
                    }
                    for (int i = 0; i < nkm.EPAT.count; i++)
                    {
                        ListViewItem n = new ListViewItem(i.ToString());
                        float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                        n.SubItems.Add(one.ToString());
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                        listView17.Items.Add(n);
                    }
                }
                nkm.AREA.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.AREA.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.AREA.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.AREA.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(two.ToString());
                    float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(three.ToString());
                    float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(four.ToString());
                    float five = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(five.ToString());
                    float six = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(six.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView18.Items.Add(n);

                    chart1.Series[9].Points.AddXY(one, three);
                    chart1.Series[9].Points[i].Color = Color.Transparent;
                    chart1.Series[9].Points[i].MarkerColor = Color.Purple;
                }
                nkm.CAME.id = br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString() + br.ReadChar().ToString();
                nkm.CAME.count = parselittle(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                if (nkm.CAME.count == 0)
                {
                    br.ReadBytes(4);
                }
                for (int i = 0; i < nkm.CAME.count; i++)
                {
                    ListViewItem n = new ListViewItem(i.ToString());
                    float one = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(one.ToString());
                    float two = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(two.ToString());
                    float three = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(three.ToString());
                    float four = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(four.ToString());
                    float five = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(five.ToString());
                    float six = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(six.ToString());
                    float seven = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(seven.ToString());
                    float eight = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(eight.ToString());
                    float nine = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(nine.ToString());
                    float ten = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(ten.ToString());
                    float elefen = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(elefen.ToString());
                    float twelfe = parselittle2(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", "")) / 4096;
                    n.SubItems.Add(twelfe.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(br.ReadBytes(4)).Replace("-", ""));
                    listView19.Items.Add(n);

                    chart1.Series[10].Points.AddXY(one, three);
                    chart1.Series[10].Points.AddXY(seven, nine);
                    chart1.Series[10].Points.AddXY(ten, twelfe);
                }
                br.Close();

            }


            else
            {
                MessageBox.Show("It isn't a nkm file or it is corrupt.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                br.Close();
            }
            //panel1.Parent = tabControl1;
        }*/
        nkmFile m;
        void Read()
        {
            Directory.CreateDirectory("img\\tmp");
            EndianBinaryReader er = new EndianBinaryReader(File.OpenRead(path_), Endianness.LittleEndian);
            m = new nkmFile();
            m.Header.Type = er.ReadString(Encoding.ASCII, 4);
            if (m.Header.Type == "NKMD")
            {
                m.Header.Unknown1 = er.ReadInt16();
                m.Header.HeaderLength = er.ReadInt16();
                m.Header.SectionOffset = new Int32[(m.Header.HeaderLength - 8) / 4];
                for (int i = 0; i < m.Header.SectionOffset.Length; i++)
                {
                    m.Header.SectionOffset[i] = er.ReadInt32();
                }
                for (int i = 0; i < m.Header.SectionOffset.Length; i++)
                {
                    er.BaseStream.Position = m.Header.SectionOffset[i] + m.Header.HeaderLength;
                    string id = er.ReadString(Encoding.ASCII, 4);
                    switch (id)
                    {
                        case "OBJI":
                            m.OBJI.ID = id;
                            m.OBJI.NrItem = er.ReadInt32();
                            m.OBJI.Items = new List<OBJi>();
                            for (int j = 0; j < m.OBJI.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.OBJI.Items.Add(new OBJi());
                                m.OBJI.Items[j].TransX = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].TransY = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].TransZ = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].RotX = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].RotY = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].RotZ = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].ScaleX = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].ScaleY = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].ScaleZ = (float)(er.ReadInt32()) / 4096f;
                                m.OBJI.Items[j].ObjectID = er.ReadBytes(2);
                                m.OBJI.Items[j].RouteID = er.ReadBytes(2);
                                m.OBJI.Items[j].Setting1 = er.ReadBytes(4);
                                m.OBJI.Items[j].Setting2 = er.ReadBytes(4);
                                m.OBJI.Items[j].Setting3 = er.ReadBytes(4);
                                m.OBJI.Items[j].Setting4 = er.ReadBytes(4);
                                m.OBJI.Items[j].Setting5 = er.ReadBytes(4);
                                n.SubItems.Add(m.OBJI.Items[j].TransX.ToString());
                                n.SubItems.Add(m.OBJI.Items[j].TransY.ToString());
                                n.SubItems.Add(m.OBJI.Items[j].TransZ.ToString());
                                n.SubItems.Add(m.OBJI.Items[j].RotX.ToString());
                                n.SubItems.Add(m.OBJI.Items[j].RotY.ToString());
                                n.SubItems.Add(m.OBJI.Items[j].RotZ.ToString());
                                n.SubItems.Add(m.OBJI.Items[j].ScaleX.ToString());
                                n.SubItems.Add(m.OBJI.Items[j].ScaleY.ToString());
                                n.SubItems.Add(m.OBJI.Items[j].ScaleZ.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[j].ObjectID).Replace("-", "") + System.BitConverter.ToString(m.OBJI.Items[j].RouteID).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[j].Setting1).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[j].Setting3).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[j].Setting4).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[j].Setting5).Replace("-", ""));
                                listView1.Items.Add(n);
                                //chart1.Series[0].Points.AddXY(m.OBJI.Items[j].TransX, m.OBJI.Items[j].TransZ);
                                if (Properties.Resources.ResourceManager.GetObject("OBJ_" + BitConverter.ToString(m.OBJI.Items[j].ObjectID).Replace("-", "") + ((m.OBJI.Items[j].ObjectID[0] == 0x6D && m.OBJI.Items[j].ObjectID[1] == 0x00) == false ? "" : "_" + BitConverter.ToInt32(m.OBJI.Items[j].Setting1, 0))) != null)
                                {
                                    nkmEditorControl1.OBJI.Add(m.OBJI.Items[j].TransX, m.OBJI.Items[j].TransY, m.OBJI.Items[j].TransZ, m.OBJI.Items[j].RotY, (Bitmap)Properties.Resources.ResourceManager.GetObject("OBJ_" + BitConverter.ToString(m.OBJI.Items[j].ObjectID).Replace("-", "") + ((m.OBJI.Items[j].ObjectID[0] == 0x6D && m.OBJI.Items[j].ObjectID[1] == 0x00) == false ? "" : "_" + BitConverter.ToInt32(m.OBJI.Items[j].Setting1, 0))));
                                }
                                else
                                {
                                    //chart1.Series[0].Points[j].MarkerColor = Color.Red;
                                    nkmEditorControl1.OBJI.Add(m.OBJI.Items[j].TransX, m.OBJI.Items[j].TransY, m.OBJI.Items[j].TransZ, m.OBJI.Items[j].RotY);
                                }
                            }
                            break;
                        case "PATH":
                            m.PATH.ID = id;
                            m.PATH.NrItem = er.ReadInt32();
                            m.PATH.Items = new List<PATh>();
                            for (int j = 0; j < m.PATH.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.PATH.Items.Add(new PATh());
                                m.PATH.Items[j].NrPoit = er.ReadBytes(4);
                                n.SubItems.Add(System.BitConverter.ToString(m.PATH.Items[j].NrPoit).Replace("-", ""));
                                listView2.Items.Add(n);
                            }
                            break;
                        case "POIT":
                            m.POIT.ID = id;
                            m.POIT.NrItem = er.ReadInt32();
                            m.POIT.Items = new List<POIt>();
                            for (int j = 0; j < m.POIT.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.POIT.Items.Add(new POIt());
                                m.POIT.Items[j].X = (float)(er.ReadInt32()) / 4096f;
                                m.POIT.Items[j].Y = (float)(er.ReadInt32()) / 4096f;
                                m.POIT.Items[j].Z = (float)(er.ReadInt32()) / 4096f;
                                m.POIT.Items[j].Nr = er.ReadByte();
                                m.POIT.Items[j].Setting1 = er.ReadBytes(3);
                                m.POIT.Items[j].Setting2 = er.ReadBytes(4);
                                n.SubItems.Add(m.POIT.Items[j].X.ToString());
                                n.SubItems.Add(m.POIT.Items[j].Y.ToString());
                                n.SubItems.Add(m.POIT.Items[j].Z.ToString());
                                n.SubItems.Add(m.POIT.Items[j].Nr.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.POIT.Items[j].Setting1).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.POIT.Items[j].Setting2).Replace("-", ""));
                                listView3.Items.Add(n);
                                nkmEditorControl1.POIT.Add(m.POIT.Items[j].X, m.POIT.Items[j].Y, m.POIT.Items[j].Z, m.POIT.Items[j].Nr);
                            }
                            break;
                        case "STAG":
                            {
                                m.STAG.ID = id;
                                m.STAG.NrItem = er.ReadInt16();
                                m.STAG.nrLap = er.ReadInt16();
                                int staglength = m.Header.SectionOffset[i + 1] - m.Header.SectionOffset[i] - 8;
                                m.STAG.data = er.ReadBytes(staglength);
                                ListViewItem n = new ListViewItem(1.ToString());
                                n.SubItems.Add(m.STAG.nrLap.ToString());
                                listView4.Items.Add(n);
                                break;
                            }
                        case "KTPS":
                            m.KTPS.ID = id;
                            m.KTPS.NrItem = er.ReadInt32();
                            m.KTPS.Items = new List<KTPs>();
                            for (int j = 0; j < m.KTPS.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.KTPS.Items.Add(new KTPs());
                                m.KTPS.Items[j].TransX = (float)(er.ReadInt32()) / 4096f;
                                m.KTPS.Items[j].TransY = (float)(er.ReadInt32()) / 4096f;
                                m.KTPS.Items[j].TransZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTPS.Items[j].RotateX = (float)(er.ReadInt32()) / 4096f;
                                m.KTPS.Items[j].RotateY = (float)(er.ReadInt32()) / 4096f;
                                m.KTPS.Items[j].RotateZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTPS.Items[j].Setting1 = er.ReadBytes(4);
                                n.SubItems.Add(m.KTPS.Items[j].TransX.ToString());
                                n.SubItems.Add(m.KTPS.Items[j].TransY.ToString());
                                n.SubItems.Add(m.KTPS.Items[j].TransZ.ToString());
                                n.SubItems.Add(m.KTPS.Items[j].RotateX.ToString());
                                n.SubItems.Add(m.KTPS.Items[j].RotateY.ToString());
                                n.SubItems.Add(m.KTPS.Items[j].RotateZ.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.KTPS.Items[j].Setting1).Replace("-", ""));
                                listView5.Items.Add(n);
                                nkmEditorControl1.KTPS.Add(m.KTPS.Items[j].TransX, m.KTPS.Items[j].TransY, m.KTPS.Items[j].TransZ, m.KTPS.Items[j].RotateY, Properties.Resources.start);
                            }
                            break;
                        case "KTPJ":
                            m.KTPJ.ID = id;
                            m.KTPJ.NrItem = er.ReadInt32();
                            m.KTPJ.Items = new List<KTPj>();
                            for (int j = 0; j < m.KTPJ.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.KTPJ.Items.Add(new KTPj());
                                m.KTPJ.Items[j].TransX = (float)(er.ReadInt32()) / 4096f;
                                m.KTPJ.Items[j].TransY = (float)(er.ReadInt32()) / 4096f;
                                m.KTPJ.Items[j].TransZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTPJ.Items[j].RotateX = (float)(er.ReadInt32()) / 4096f;
                                m.KTPJ.Items[j].RotateY = (float)(er.ReadInt32()) / 4096f;
                                m.KTPJ.Items[j].RotateZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTPJ.Items[j].Setting1 = er.ReadBytes(4);
                                if ((m.Header.SectionOffset[i + 1] - m.Header.SectionOffset[i] - 8) / 32 == m.KTPJ.NrItem)
                                {
                                    m.KTPJ.Items[j].Setting2 = er.ReadBytes(4);
                                }
                                else
                                {
                                    m.KTPJ.Items[j].Setting2 = inttobyte(j);
                                }
                                n.SubItems.Add(m.KTPJ.Items[j].TransX.ToString());
                                n.SubItems.Add(m.KTPJ.Items[j].TransY.ToString());
                                n.SubItems.Add(m.KTPJ.Items[j].TransZ.ToString());
                                n.SubItems.Add(m.KTPJ.Items[j].RotateX.ToString());
                                n.SubItems.Add(m.KTPJ.Items[j].RotateY.ToString());
                                n.SubItems.Add(m.KTPJ.Items[j].RotateZ.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.KTPJ.Items[j].Setting1).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.KTPJ.Items[j].Setting2).Replace("-", ""));
                                listView6.Items.Add(n);
                                nkmEditorControl1.KTPJ.Add(m.KTPJ.Items[j].TransX, m.KTPJ.Items[j].TransY, m.KTPJ.Items[j].TransZ, Color.Orange);
                            }
                            break;
                        case "KTP2":
                            m.KTP2.ID = id;
                            m.KTP2.NrItem = er.ReadInt32();
                            m.KTP2.Items = new List<KTP2>();
                            for (int j = 0; j < m.KTP2.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.KTP2.Items.Add(new KTP2());
                                m.KTP2.Items[j].TransX = (float)(er.ReadInt32()) / 4096f;
                                m.KTP2.Items[j].TransY = (float)(er.ReadInt32()) / 4096f;
                                m.KTP2.Items[j].TransZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTP2.Items[j].RotateX = (float)(er.ReadInt32()) / 4096f;
                                m.KTP2.Items[j].RotateY = (float)(er.ReadInt32()) / 4096f;
                                m.KTP2.Items[j].RotateZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTP2.Items[j].Setting1 = er.ReadBytes(4);
                                n.SubItems.Add(m.KTP2.Items[j].TransX.ToString());
                                n.SubItems.Add(m.KTP2.Items[j].TransY.ToString());
                                n.SubItems.Add(m.KTP2.Items[j].TransZ.ToString());
                                n.SubItems.Add(m.KTP2.Items[j].RotateX.ToString());
                                n.SubItems.Add(m.KTP2.Items[j].RotateY.ToString());
                                n.SubItems.Add(m.KTP2.Items[j].RotateZ.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.KTP2.Items[j].Setting1).Replace("-", ""));
                                listView7.Items.Add(n);
                                nkmEditorControl1.KTP2.Add(m.KTP2.Items[j].TransX, m.KTP2.Items[j].TransY, m.KTP2.Items[j].TransZ, Color.LightSkyBlue);
                            }
                            break;
                        case "KTPC":
                            m.KTPC.ID = id;
                            m.KTPC.NrItem = er.ReadInt32();
                            m.KTPC.Items = new List<KTPc>();
                            for (int j = 0; j < m.KTPC.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.KTPC.Items.Add(new KTPc());
                                m.KTPC.Items[j].TransX = (float)(er.ReadInt32()) / 4096f;
                                m.KTPC.Items[j].TransY = (float)(er.ReadInt32()) / 4096f;
                                m.KTPC.Items[j].TransZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTPC.Items[j].RotateX = (float)(er.ReadInt32()) / 4096f;
                                m.KTPC.Items[j].RotateY = (float)(er.ReadInt32()) / 4096f;
                                m.KTPC.Items[j].RotateZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTPC.Items[j].Setting1 = er.ReadBytes(4);
                                n.SubItems.Add(m.KTPC.Items[j].TransX.ToString());
                                n.SubItems.Add(m.KTPC.Items[j].TransY.ToString());
                                n.SubItems.Add(m.KTPC.Items[j].TransZ.ToString());
                                n.SubItems.Add(m.KTPC.Items[j].RotateX.ToString());
                                n.SubItems.Add(m.KTPC.Items[j].RotateY.ToString());
                                n.SubItems.Add(m.KTPC.Items[j].RotateZ.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.KTPC.Items[j].Setting1).Replace("-", ""));
                                listView8.Items.Add(n);
                                nkmEditorControl1.KTPC.Add(m.KTPC.Items[j].TransX, m.KTPC.Items[j].TransY, m.KTPC.Items[j].TransZ, Color.DeepPink);
                            }
                            break;
                        case "KTPM":
                            m.KTPM.ID = id;
                            m.KTPM.NrItem = er.ReadInt32();
                            m.KTPM.Items = new List<KTPm>();
                            for (int j = 0; j < m.KTPM.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.KTPM.Items.Add(new KTPm());
                                m.KTPM.Items[j].TransX = (float)(er.ReadInt32()) / 4096f;
                                m.KTPM.Items[j].TransY = (float)(er.ReadInt32()) / 4096f;
                                m.KTPM.Items[j].TransZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTPM.Items[j].RotateX = (float)(er.ReadInt32()) / 4096f;
                                m.KTPM.Items[j].RotateY = (float)(er.ReadInt32()) / 4096f;
                                m.KTPM.Items[j].RotateZ = (float)(er.ReadInt32()) / 4096f;
                                m.KTPM.Items[j].Setting1 = er.ReadBytes(4);
                                n.SubItems.Add(m.KTPM.Items[j].TransX.ToString());
                                n.SubItems.Add(m.KTPM.Items[j].TransY.ToString());
                                n.SubItems.Add(m.KTPM.Items[j].TransZ.ToString());
                                n.SubItems.Add(m.KTPM.Items[j].RotateX.ToString());
                                n.SubItems.Add(m.KTPM.Items[j].RotateY.ToString());
                                n.SubItems.Add(m.KTPM.Items[j].RotateZ.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.KTPM.Items[j].Setting1).Replace("-", ""));
                                listView9.Items.Add(n);
                                nkmEditorControl1.KTPM.Add(m.KTPM.Items[j].TransX, m.KTPM.Items[j].TransY, m.KTPM.Items[j].TransZ, Color.Purple);
                            }
                            break;
                        case "CPOI":
                            m.CPOI.ID = id;
                            m.CPOI.NrItem = er.ReadInt32();
                            m.CPOI.Items = new List<CPOi>();
                            for (int j = 0; j < m.CPOI.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.CPOI.Items.Add(new CPOi());
                                m.CPOI.Items[j].X1 = (float)(er.ReadInt32()) / 4096f;
                                m.CPOI.Items[j].Y1 = (float)(er.ReadInt32()) / 4096f;
                                m.CPOI.Items[j].X2 = (float)(er.ReadInt32()) / 4096f;
                                m.CPOI.Items[j].Y2 = (float)(er.ReadInt32()) / 4096f;
                                m.CPOI.Items[j].Setting1 = er.ReadBytes(4);
                                m.CPOI.Items[j].Setting2 = er.ReadBytes(4);
                                m.CPOI.Items[j].Setting3 = er.ReadBytes(4);
                                m.CPOI.Items[j].SData = er.ReadBytes(4);
                                m.CPOI.Items[j].LRespawn = er.ReadBytes(4);
                                n.SubItems.Add(m.CPOI.Items[j].X1.ToString());
                                n.SubItems.Add(m.CPOI.Items[j].Y1.ToString());
                                n.SubItems.Add(m.CPOI.Items[j].X2.ToString());
                                n.SubItems.Add(m.CPOI.Items[j].Y2.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.CPOI.Items[j].Setting1).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CPOI.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CPOI.Items[j].Setting3).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CPOI.Items[j].SData).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CPOI.Items[j].LRespawn).Replace("-", ""));
                                listView10.Items.Add(n);
                                nkmEditorControl1.CPOI.Add(m.CPOI.Items[j].X1, m.CPOI.Items[j].Y1, m.CPOI.Items[j].X2, m.CPOI.Items[j].Y2);
                            }
                            break;
                        case "CPAT":
                            m.CPAT.ID = id;
                            m.CPAT.NrItem = er.ReadInt32();
                            m.CPAT.Items = new List<CPAt>();
                            for (int j = 0; j < m.CPAT.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.CPAT.Items.Add(new CPAt());
                                m.CPAT.Items[j].Setting1 = (float)(er.ReadInt32()) / 4096f;
                                m.CPAT.Items[j].Setting2 = er.ReadBytes(4);
                                m.CPAT.Items[j].Setting3 = er.ReadBytes(4);
                                n.SubItems.Add(m.CPAT.Items[j].Setting1.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.CPAT.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CPAT.Items[j].Setting3).Replace("-", ""));
                                listView11.Items.Add(n);
                            }
                            break;
                        case "IPOI":
                            m.IPOI.ID = id;
                            m.IPOI.NrItem = er.ReadInt32();
                            m.IPOI.Items = new List<IPOi>();
                            for (int j = 0; j < m.IPOI.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.IPOI.Items.Add(new IPOi());
                                m.IPOI.Items[j].X = (float)(er.ReadInt32()) / 4096f;
                                m.IPOI.Items[j].Y = (float)(er.ReadInt32()) / 4096f;
                                m.IPOI.Items[j].Z = (float)(er.ReadInt32()) / 4096f;
                                //m.IPOI.Items[j].Nr = er.ReadInt16();
                                m.IPOI.Items[j].Setting1 = er.ReadBytes(4);
                                if ((m.Header.SectionOffset[i + 1] - m.Header.SectionOffset[i] - 8) / 20 == m.IPOI.NrItem)
                                {
                                    m.IPOI.Items[j].Setting2 = er.ReadBytes(4);
                                }
                                else
                                {
                                    m.IPOI.Items[j].Setting2 = new byte[4];
                                }
                                n.SubItems.Add(m.IPOI.Items[j].X.ToString());
                                n.SubItems.Add(m.IPOI.Items[j].Y.ToString());
                                n.SubItems.Add(m.IPOI.Items[j].Z.ToString());
                                //n.SubItems.Add(m.IPOI.Items[j].Nr.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.IPOI.Items[j].Setting1).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.IPOI.Items[j].Setting2).Replace("-", ""));
                                listView12.Items.Add(n);
                                nkmEditorControl1.IPOI.Add(m.IPOI.Items[j].X, m.IPOI.Items[j].Y, m.IPOI.Items[j].Z, 0);
                            }
                            break;
                        case "IPAT":
                            m.IPAT.ID = id;
                            m.IPAT.NrItem = er.ReadInt32();
                            m.IPAT.Items = new List<IPAt>();
                            for (int j = 0; j < m.IPAT.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.IPAT.Items.Add(new IPAt());
                                m.IPAT.Items[j].Setting1 = (float)(er.ReadInt32()) / 4096f;
                                m.IPAT.Items[j].Setting2 = er.ReadBytes(4);
                                m.IPAT.Items[j].Setting3 = er.ReadBytes(4);
                                n.SubItems.Add(m.IPAT.Items[j].Setting1.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.IPAT.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.IPAT.Items[j].Setting3).Replace("-", ""));
                                listView13.Items.Add(n);
                            }
                            break;
                        case "EPOI":
                            m.EPOI.ID = id;
                            m.EPOI.NrItem = er.ReadInt32();
                            m.EPOI.Items = new List<EPOi>();
                            for (int j = 0; j < m.EPOI.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.EPOI.Items.Add(new EPOi());
                                m.EPOI.Items[j].X = (float)(er.ReadInt32()) / 4096f;
                                m.EPOI.Items[j].Y = (float)(er.ReadInt32()) / 4096f;
                                m.EPOI.Items[j].Z = (float)(er.ReadInt32()) / 4096f;
                                m.EPOI.Items[j].Setting1 = er.ReadBytes(4);
                                m.EPOI.Items[j].Setting2 = er.ReadBytes(4);
                                m.EPOI.Items[j].Setting3 = er.ReadBytes(4);
                                n.SubItems.Add(m.EPOI.Items[j].X.ToString());
                                n.SubItems.Add(m.EPOI.Items[j].Y.ToString());
                                n.SubItems.Add(m.EPOI.Items[j].Z.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.EPOI.Items[j].Setting1).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.EPOI.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.EPOI.Items[j].Setting3).Replace("-", ""));
                                listView14.Items.Add(n);
                                nkmEditorControl1.EPOI.Add(m.EPOI.Items[j].X, m.EPOI.Items[j].Y, m.EPOI.Items[j].Z, 0);
                            }
                            break;
                        case "EPAT":
                            m.EPAT.ID = id;
                            m.EPAT.NrItem = er.ReadInt32();
                            m.EPAT.Items = new List<EPAt>();
                            for (int j = 0; j < m.EPAT.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.EPAT.Items.Add(new EPAt());
                                m.EPAT.Items[j].Setting1 = (float)(er.ReadInt32()) / 4096f;
                                m.EPAT.Items[j].Setting2 = er.ReadBytes(4);
                                m.EPAT.Items[j].Setting3 = er.ReadBytes(4);
                                n.SubItems.Add(m.EPAT.Items[j].Setting1.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.EPAT.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.EPAT.Items[j].Setting3).Replace("-", ""));
                                listView15.Items.Add(n);
                            }
                            break;
                        case "MEPO":
                            m.MEPO.ID = id;
                            m.MEPO.NrItem = er.ReadInt32();
                            m.MEPO.Items = new List<MEPo>();
                            for (int j = 0; j < m.MEPO.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.MEPO.Items.Add(new MEPo());
                                m.MEPO.Items[j].X = (float)(er.ReadInt32()) / 4096f;
                                m.MEPO.Items[j].Y = (float)(er.ReadInt32()) / 4096f;
                                m.MEPO.Items[j].Z = (float)(er.ReadInt32()) / 4096f;
                                m.MEPO.Items[j].Setting1 = er.ReadBytes(4);
                                m.MEPO.Items[j].Setting2 = er.ReadBytes(4);
                                m.MEPO.Items[j].Setting3 = er.ReadBytes(4);
                                n.SubItems.Add(m.MEPO.Items[j].X.ToString());
                                n.SubItems.Add(m.MEPO.Items[j].Y.ToString());
                                n.SubItems.Add(m.MEPO.Items[j].Z.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.MEPO.Items[j].Setting1).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.MEPO.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.MEPO.Items[j].Setting3).Replace("-", ""));
                                listView16.Items.Add(n);
                                nkmEditorControl1.MEPO.Add(m.MEPO.Items[j].X, m.MEPO.Items[j].Y, m.MEPO.Items[j].Z, 0);
                            }
                            break;
                        case "MEPA":
                            m.MEPA.ID = id;
                            m.MEPA.NrItem = er.ReadInt32();
                            m.MEPA.Items = new List<MEPa>();
                            for (int j = 0; j < m.MEPA.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.MEPA.Items.Add(new MEPa());
                                m.MEPA.Items[j].Setting1 = (float)(er.ReadInt32()) / 4096f;
                                m.MEPA.Items[j].Setting2 = er.ReadBytes(4);
                                m.MEPA.Items[j].Setting3 = er.ReadBytes(4);
                                m.MEPA.Items[j].Setting4 = er.ReadBytes(4);
                                m.MEPA.Items[j].Setting5 = er.ReadBytes(4);
                                n.SubItems.Add(m.MEPA.Items[j].Setting1.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.MEPA.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.MEPA.Items[j].Setting3).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.MEPA.Items[j].Setting4).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.MEPA.Items[j].Setting5).Replace("-", ""));
                                listView17.Items.Add(n);
                            }
                            break;
                        case "AREA":
                            m.AREA.ID = id;
                            m.AREA.NrItem = er.ReadInt32();
                            m.AREA.Items = new List<AREa>();
                            for (int j = 0; j < m.AREA.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.AREA.Items.Add(new AREa());
                                m.AREA.Items[j].TransX = (float)(er.ReadInt32()) / 4096f;
                                m.AREA.Items[j].TransY = (float)(er.ReadInt32()) / 4096f;
                                m.AREA.Items[j].TransZ = (float)(er.ReadInt32()) / 4096f;
                                m.AREA.Items[j].Setting1 = (float)(er.ReadInt32()) / 4096f;
                                m.AREA.Items[j].Setting2 = (float)(er.ReadInt32()) / 4096f;
                                m.AREA.Items[j].Setting3 = (float)(er.ReadInt32()) / 4096f;
                                m.AREA.Items[j].Setting4 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting5 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting6 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting7 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting8 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting9 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting10 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting11 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting12 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting13 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting14 = er.ReadBytes(4);
                                m.AREA.Items[j].Setting15 = er.ReadBytes(4);
                                n.SubItems.Add(m.AREA.Items[j].TransX.ToString());
                                n.SubItems.Add(m.AREA.Items[j].TransY.ToString());
                                n.SubItems.Add(m.AREA.Items[j].TransZ.ToString());
                                n.SubItems.Add(m.AREA.Items[j].Setting1.ToString());
                                n.SubItems.Add(m.AREA.Items[j].Setting2.ToString());
                                n.SubItems.Add(m.AREA.Items[j].Setting3.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting4).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting5).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting6).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting7).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting8).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting9).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting10).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting11).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting12).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting13).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting14).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.AREA.Items[j].Setting15).Replace("-", ""));
                                listView18.Items.Add(n);
                                nkmEditorControl1.AREA.Add(m.AREA.Items[j].TransX, m.AREA.Items[j].TransY, m.AREA.Items[j].TransZ, 0);
                            }
                            break;
                        case "CAME":
                            m.CAME.ID = id;
                            m.CAME.NrItem = er.ReadInt32();
                            m.CAME.Items = new List<CAMe>();
                            for (int j = 0; j < m.CAME.NrItem; j++)
                            {
                                ListViewItem n = new ListViewItem((j + 1).ToString());
                                m.CAME.Items.Add(new CAMe());
                                m.CAME.Items[j].X1 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Y1 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Z1 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Zero1 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Zero1 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Zero1 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].X2 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Y2 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Z2 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].X3 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Y3 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Z3 = (float)(er.ReadInt32()) / 4096f;
                                m.CAME.Items[j].Setting1 = er.ReadBytes(4);
                                m.CAME.Items[j].Setting2 = er.ReadBytes(4);
                                m.CAME.Items[j].Setting3 = er.ReadBytes(4);
                                m.CAME.Items[j].Setting4 = er.ReadBytes(4);
                                m.CAME.Items[j].Setting5 = er.ReadBytes(4);
                                m.CAME.Items[j].Setting6 = er.ReadBytes(4);
                                m.CAME.Items[j].Setting7 = er.ReadBytes(4);
                                n.SubItems.Add(m.CAME.Items[j].X1.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Y1.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Z1.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Zero1.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Zero1.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Zero1.ToString());
                                n.SubItems.Add(m.CAME.Items[j].X2.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Y2.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Z2.ToString());
                                n.SubItems.Add(m.CAME.Items[j].X3.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Y3.ToString());
                                n.SubItems.Add(m.CAME.Items[j].Z3.ToString());
                                n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[j].Setting1).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[j].Setting2).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[j].Setting3).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[j].Setting4).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[j].Setting5).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[j].Setting6).Replace("-", ""));
                                n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[j].Setting7).Replace("-", ""));
                                listView19.Items.Add(n);
                                nkmEditorControl1.CAME.Add(m.CAME.Items[j].X1, m.CAME.Items[j].Y1, m.CAME.Items[j].Z1, m.CAME.Items[j].X2, m.CAME.Items[j].Y2, m.CAME.Items[j].Z2, m.CAME.Items[j].X3, m.CAME.Items[j].Y3, m.CAME.Items[j].Z3);
                            }
                            break;
                        default:
                            MessageBox.Show("error");
                            er.Close();
                            this.Close();
                            return;
                            break;
                    }
                }
                er.Close();
            }
            else
            {
                
            }
        }
        public struct nkmFile
        {
            public header Header;
            public struct header
            {
                public string Type;
                public short Unknown1;
                public short HeaderLength;
                public Int32[] SectionOffset;
            }
            public obji OBJI;
            public struct obji
            {
                public string ID;
                public Int32 NrItem;
                public List<OBJi> Items;
            }
            public path PATH;
            public struct path
            {
                public string ID;
                public Int32 NrItem;
                public List<PATh> Items;
            }
            public poit POIT;
            public struct poit
            {
                public string ID;
                public Int32 NrItem;
                public List<POIt> Items;
            }
            public stag STAG;
            public struct stag
            {
                public string ID;
                public Int16 NrItem;
                public Int16 nrLap;
                public byte[] data;
            }
            public ktps KTPS;
            public struct ktps
            {
                public string ID;
                public Int32 NrItem;
                public List<KTPs> Items;
            }
            public ktpj KTPJ;
            public struct ktpj
            {
                public string ID;
                public Int32 NrItem;
                public List<KTPj> Items;
            }
            public ktp2 KTP2;
            public struct ktp2
            {
                public string ID;
                public Int32 NrItem;
                public List<KTP2> Items;
            }
            public ktpc KTPC;
            public struct ktpc
            {
                public string ID;
                public Int32 NrItem;
                public List<KTPc> Items;
            }
            public ktpm KTPM;
            public struct ktpm
            {
                public string ID;
                public Int32 NrItem;
                public List<KTPm> Items;
            }
            public cpoi CPOI;
            public struct cpoi
            {
                public string ID;
                public Int32 NrItem;
                public List<CPOi> Items;
            }
            public cpat CPAT;
            public struct cpat
            {
                public string ID;
                public Int32 NrItem;
                public List<CPAt> Items;
            }
            public ipoi IPOI;
            public struct ipoi
            {
                public string ID;
                public Int32 NrItem;
                public List<IPOi> Items;
            }
            public ipat IPAT;
            public struct ipat
            {
                public string ID;
                public Int32 NrItem;
                public List<IPAt> Items;
            }
            public epoi EPOI;
            public struct epoi
            {
                public string ID;
                public Int32 NrItem;
                public List<EPOi> Items;
            }
            public epat EPAT;
            public struct epat
            {
                public string ID;
                public Int32 NrItem;
                public List<EPAt> Items;
            }
            public mepo MEPO;
            public struct mepo
            {
                public string ID;
                public Int32 NrItem;
                public List<MEPo> Items;
            }
            public mepa MEPA;
            public struct mepa
            {
                public string ID;
                public Int32 NrItem;
                public List<MEPa> Items;
            }
            public area AREA;
            public struct area
            {
                public string ID;
                public Int32 NrItem;
                public List<AREa> Items;
            }
            public came CAME;
            public struct came
            {
                public string ID;
                public Int32 NrItem;
                public List<CAMe> Items;
            }
        }
        public class OBJi
        {
            public float TransX;
            public float TransY;
            public float TransZ;
            public float RotX;
            public float RotY;
            public float RotZ;
            public float ScaleX;
            public float ScaleY;
            public float ScaleZ;
            public byte[] ObjectID;
            public byte[] RouteID;
            public byte[] Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
            public byte[] Setting4;
            public byte[] Setting5;
        }
        public class PATh
        {
            public byte[] NrPoit;
        }
        public class POIt
        {
            public float X;
            public float Y;
            public float Z;
            public int Nr;
            public byte[] Setting1;
            public byte[] Setting2;
        }
        public class KTPs
        {
            public float TransX;
            public float TransY;
            public float TransZ;
            public float RotateX;
            public float RotateY;
            public float RotateZ;
            public byte[] Setting1;
        }
        public class KTPj
        {
            public float TransX;
            public float TransY;
            public float TransZ;
            public float RotateX;
            public float RotateY;
            public float RotateZ;
            public byte[] Setting1;
            public byte[] Setting2;
        }
        public class KTP2
        {
            public float TransX;
            public float TransY;
            public float TransZ;
            public float RotateX;
            public float RotateY;
            public float RotateZ;
            public byte[] Setting1;
        }
        public class KTPc
        {
            public float TransX;
            public float TransY;
            public float TransZ;
            public float RotateX;
            public float RotateY;
            public float RotateZ;
            public byte[] Setting1;
        }
        public class KTPm
        {
            public float TransX;
            public float TransY;
            public float TransZ;
            public float RotateX;
            public float RotateY;
            public float RotateZ;
            public byte[] Setting1;
        }
        public class CPOi
        {
            public float X1;
            public float Y1;
            public float X2;
            public float Y2;
            public byte[] Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
            public byte[] SData;
            public byte[] LRespawn;
        }
        public class CPAt
        {
            public float Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
        }
        public class IPOi
        {
            public float X;
            public float Y;
            public float Z;
            //public int Nr;
            public byte[] Setting1;
            public byte[] Setting2;
        }
        public class IPAt
        {
            public float Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
        }
        public class EPOi
        {
            public float X;
            public float Y;
            public float Z;
            public byte[] Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
        }
        public class EPAt
        {
            public float Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
        }
        public class MEPo
        {
            public float X;
            public float Y;
            public float Z;
            public byte[] Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
        }
        public class MEPa
        {
            public float Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
            public byte[] Setting4;
            public byte[] Setting5;
        }
        public class AREa
        {
            public float TransX;
            public float TransY;
            public float TransZ;
            public float Setting1;
            public float Setting2;
            public float Setting3;
            public byte[] Setting4;
            public byte[] Setting5;
            public byte[] Setting6;
            public byte[] Setting7;
            public byte[] Setting8;
            public byte[] Setting9;
            public byte[] Setting10;
            public byte[] Setting11;
            public byte[] Setting12;
            public byte[] Setting13;
            public byte[] Setting14;
            public byte[] Setting15;
        }
        public class CAMe
        {
            public float X1;
            public float Y1;
            public float Z1;
            public float Zero1;
            public float Zero2;
            public float Zero3;
            public float X2;
            public float Y2;
            public float Z2;
            public float X3;
            public float Y3;
            public float Z3;
            public byte[] Setting1;
            public byte[] Setting2;
            public byte[] Setting3;
            public byte[] Setting4;
            public byte[] Setting5;
            public byte[] Setting6;
            public byte[] Setting7;
        }
        int parselittle(string input)
        {
            int test = 0;
            test = int.Parse(input.ToCharArray()[6].ToString() + input.ToCharArray()[7].ToString() + input.ToCharArray()[4].ToString() + input.ToCharArray()[5].ToString() + input.ToCharArray()[2].ToString() + input.ToCharArray()[3].ToString() + input.ToCharArray()[0].ToString() + input.ToCharArray()[1].ToString(), System.Globalization.NumberStyles.HexNumber);
            return test;
        }
        float parselittle2(string input)
        {
            float test2 = 0;
            test2 = int.Parse(input.ToCharArray()[6].ToString() + input.ToCharArray()[7].ToString() + input.ToCharArray()[4].ToString() + input.ToCharArray()[5].ToString() + input.ToCharArray()[2].ToString() + input.ToCharArray()[3].ToString() + input.ToCharArray()[0].ToString() + input.ToCharArray()[1].ToString(), System.Globalization.NumberStyles.HexNumber);
            return test2;
        }
        public static Bitmap RotateImg(Bitmap bmp, float angle, Color bkColor)
        {
            int w = bmp.Width;
            int h = bmp.Height;
            PixelFormat pf = default(PixelFormat);
            if (bkColor == Color.Transparent)
            {
                pf = PixelFormat.Format32bppArgb;
            }
            else
            {
                pf = bmp.PixelFormat;
            }

            Bitmap tempImg = new Bitmap(w, h, pf);
            Graphics g = Graphics.FromImage(tempImg);
            g.Clear(bkColor);
            g.DrawImageUnscaled(bmp, 1, 1);
            g.Dispose();

            GraphicsPath path = new GraphicsPath();
            path.AddRectangle(new RectangleF(0f, 0f, w, h));
            Matrix mtrx = new Matrix();
            //Using System.Drawing.Drawing2D.Matrix class 
            mtrx.Rotate(angle);
            RectangleF rct = path.GetBounds(mtrx);
            Bitmap newImg = new Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf);
            g = Graphics.FromImage(newImg);
            g.Clear(bkColor);
            g.TranslateTransform(-rct.X, -rct.Y);
            g.RotateTransform(angle);
            g.InterpolationMode = InterpolationMode.HighQualityBilinear;
            g.DrawImageUnscaled(tempImg, 0, 0);
            g.Dispose();
            tempImg.Dispose();
            return newImg;
        }

        private void nkm_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
            Directory.Delete("img\\tmp", true);
        }

        private void slider1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void oBJIToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void oBJIToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void oBJIToolStripMenuItem_CheckStateChanged(object sender, EventArgs e)
        {
            if (oBJIToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.obji = false;
                //chart1.Series[0].Enabled = false;
            }
            else
            {
                nkmEditorControl1.obji = true;
                //chart1.Series[0].Enabled = true;
            }
        }

        private void pOITToolStripMenuItem_CheckStateChanged(object sender, EventArgs e)
        {
            if (pOITToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.poit = false;
               // chart1.Series[1].Enabled = false;
            }
            else
            {
                nkmEditorControl1.poit = true;
               // chart1.Series[1].Enabled = true;
            }
        }

        private void kTPSToolStripMenuItem_CheckStateChanged(object sender, EventArgs e)
        {
            if (kTPSToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.ktps = false;
                //chart1.Series[2].Enabled = false;
            }
            else
            {
                nkmEditorControl1.ktps = true;
                //chart1.Series[2].Enabled = true;
            }
        }

        private void kTPJToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void kTPJToolStripMenuItem_CheckStateChanged(object sender, EventArgs e)
        {
            if (kTPJToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.ktpj = false;
                //chart1.Series[3].Enabled = false;
            }
            else
            {
                nkmEditorControl1.ktpj = true;
                //chart1.Series[3].Enabled = true;
            }
        }

        private void kTP2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (kTP2ToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.ktp2 = false;
                //chart1.Series[4].Enabled = false;
            }
            else
            {
                nkmEditorControl1.ktp2 = true;
                //chart1.Series[4].Enabled = true;
            }
        }

        private void kTPCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (kTPCToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.ktpc = false;
                //chart1.Series[5].Enabled = false;
            }
            else
            {
                nkmEditorControl1.ktpc = true;
                //chart1.Series[5].Enabled = true;
            }
        }

        private void cPOIToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (cPOIToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.cpoi = false;
                //chart1.Series[6].Enabled = false;
            }
            else
            {
                nkmEditorControl1.cpoi = true;
                //chart1.Series[6].Enabled = true;
            }
        }

        private void iPOIToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (iPOIToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.ipoi = false;
                //chart1.Series[7].Enabled = false;
            }
            else
            {
                nkmEditorControl1.ipoi = true;
                //chart1.Series[7].Enabled = true;
            }
        }

        private void ePOIToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ePOIToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.epoi_mepo = false;
                //chart1.Series[8].Enabled = false;
            }
            else
            {
                nkmEditorControl1.epoi_mepo = true;
                //chart1.Series[8].Enabled = true;
            }
        }

        private void aREAToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (aREAToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.area = false;
                //chart1.Series[9].Enabled = false;
            }
            else
            {
                nkmEditorControl1.area = true;
                //chart1.Series[9].Enabled = true;
            }
        }

        private void cAMEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (cAMEToolStripMenuItem.CheckState == CheckState.Unchecked)
            {
                nkmEditorControl1.came = false;
                //chart1.Series[10].Enabled = false;
            }
            else
            {
                nkmEditorControl1.came = true;
                //chart1.Series[10].Enabled = true;
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ListViewItem t = new ListViewItem((listView1.Items.Count+1).ToString());
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("1");
            t.SubItems.Add("1");
            t.SubItems.Add("1");
            t.SubItems.Add("6500FFFF");
            t.SubItems.Add("00000000");
            t.SubItems.Add("00000000");
            t.SubItems.Add("00000000");
            t.SubItems.Add("00000000");
            t.SubItems.Add("00000000");
            listView1.Items.Add(t);
            OBJi o = new OBJi();
            o.TransX = 0;
            o.TransY = 0;
            o.TransZ = 0;
            o.RotX = 0;
            o.RotY = 0;
            o.RotZ = 0;
            o.ScaleX = 1;
            o.ScaleY = 1;
            o.ScaleZ = 1;
            o.ObjectID = new byte[] { 0x65, 0x00 };
            o.RouteID = new byte[] { 0xFF, 0xFF };
            o.Setting1 = new byte[4];
            o.Setting2 = new byte[4];
            o.Setting3 = new byte[4];
            o.Setting4 = new byte[4];
            o.Setting5 = new byte[4];
            m.OBJI.Items.Add(o);
            nkmEditorControl1.OBJI.Add(0, 0, 0, 0, Properties.Resources.OBJ_6500);
            //chart1.Series[0].Points.AddXY(0, 0);
            //chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].Color = Color.Transparent;
            //chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].MarkerImage = "img\\box.png";
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices.Count != 0)
            {
                //chart1.Series[0].Points.RemoveAt(listView1.SelectedIndices[0]);
                m.OBJI.Items.RemoveAt(listView1.SelectedIndices[0]);
                nkmEditorControl1.OBJI.RemoveAt(listView1.SelectedIndices[0]);
                listView1.Items.RemoveAt(listView1.SelectedIndices[0]);
            }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices.Count == 0)
            {
                toolStripButton2.Enabled = false;
                toolStripButton3.Enabled = false;
                toolStripButton20.Enabled = false;
                propertyGrid1.SelectedObject = null;
            }
            else
            {
                toolStripButton2.Enabled = true;
                toolStripButton3.Enabled = true;
                toolStripButton20.Enabled = true;
                NKMObject p = new NKMObject();
                p.X = m.OBJI.Items[listView1.SelectedIndices[0]].TransX;
                p.Y = m.OBJI.Items[listView1.SelectedIndices[0]].TransY;
                p.Z = m.OBJI.Items[listView1.SelectedIndices[0]].TransZ;
                p.Xrot = m.OBJI.Items[listView1.SelectedIndices[0]].RotX;
                p.Yrot = m.OBJI.Items[listView1.SelectedIndices[0]].RotY;
                p.Zrot = m.OBJI.Items[listView1.SelectedIndices[0]].RotZ;
                p.Xsca = m.OBJI.Items[listView1.SelectedIndices[0]].ScaleX;
                p.Ysca = m.OBJI.Items[listView1.SelectedIndices[0]].ScaleY;
                p.Zsca = m.OBJI.Items[listView1.SelectedIndices[0]].ScaleZ;
                p.SetObjectID(m.OBJI.Items[listView1.SelectedIndices[0]].ObjectID);
                propertyGrid1.SelectedObject = p;
            }
        }
        public class NKMObject
        {
            public void SetObjectID(byte[] Type)
            {
                ct = Type;
            }
            [Category("Position"), DefaultValue(0), DisplayName("X"), Description("The X position.")]
            public float X
            {
                get;
                set;
            }
            [Category("Position"), DefaultValue(0), DisplayName("Y"), Description("The Y position.")]
            public float Y
            {
                get;
                set;
            }
            [Category("Position"), DefaultValue(0), DisplayName("Z"), Description("The Z position.")]
            public float Z
            {
                get;
                set;
            }
            [Category("Rotation"), DefaultValue(0), DisplayName("X"), Description("Rotation around the X angle.")]
            public float Xrot
            {
                get;
                set;
            }
            [Category("Rotation"), DefaultValue(0), DisplayName("Y"), Description("Rotation around the Y angle.")]
            public float Yrot
            {
                get;
                set;
            }
            [Category("Rotation"), DefaultValue(0), DisplayName("Z"), Description("Rotation around the Z angle.")]
            public float Zrot
            {
                get;
                set;
            }
            [Category("Scale"), DefaultValue(0), DisplayName("X"), Description("The X scale.")]
            public float Xsca
            {
                get;
                set;
            }
            [Category("Scale"), DefaultValue(0), DisplayName("Y"), Description("The Y scale.")]
            public float Ysca
            {
                get;
                set;
            }
            [Category("Scale"), DefaultValue(0), DisplayName("Z"), Description("The Z scale.")]
            public float Zsca
            {
                get;
                set;
            }
            private byte[] ct;
            [Category("Object Properties"), DefaultValue(0), DisplayName("Object ID"), TypeConverter(typeof(UInt16HexTypeConverter)), Description("The object ID."), Editor(typeof(NKMObjectEditor), typeof(UITypeEditor))] 
            public UInt16 ObjectID
            {
                get { return UInt16.Parse(BitConverter.ToString(ct).Replace("-", ""), System.Globalization.NumberStyles.HexNumber); }
                set
                {
                    ct = stringtobyte(string.Format("{0:x4}", value));
                }
            }
        }
        public class KTPSObject
        {
            [Category("Position"), DefaultValue(0), DisplayName("X"), Description("The X position.")]
            public float X
            {
                get;
                set;
            }
            [Category("Position"), DefaultValue(0), DisplayName("Y"), Description("The Y position.")]
            public float Y
            {
                get;
                set;
            }
            [Category("Position"), DefaultValue(0), DisplayName("Z"), Description("The Z position.")]
            public float Z
            {
                get;
                set;
            }
            [Category("Rotation"), DefaultValue(0), DisplayName("X"), Description("Rotation around the X angle.")]
            public float Xrot
            {
                get;
                set;
            }
            [Category("Rotation"), DefaultValue(0), DisplayName("Y"), Description("Rotation around the Y angle.")]
            public float Yrot
            {
                get;
                set;
            }
            [Category("Rotation"), DefaultValue(0), DisplayName("Z"), Description("Rotation around the Z angle.")]
            public float Zrot
            {
                get;
                set;
            }
        }
        public class UInt16HexTypeConverter : TypeConverter
        {
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                if (sourceType == typeof(string))
                {
                    return true;
                }
                else
                {
                    return base.CanConvertFrom(context, sourceType);
                }
            }

            public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
            {
                if (destinationType == typeof(string))
                {
                    return true;
                }
                else
                {
                    return base.CanConvertTo(context, destinationType);
                }
            }

            public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
            {
                if (destinationType == typeof(string) && value.GetType() == typeof(UInt16))
                {
                    string t = string.Format("{0:X4}", value);
                    for (int i = 0; i < 4 - t.Length; i++)
                    {
                        t += "0";
                    }
                    return t;
                }
                else
                {
                    return base.ConvertTo(context, culture, value, destinationType);
                }
            }

            public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
            {
                if (value.GetType() == typeof(string))
                {
                    string input = (string)value;

                    if (input.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                    {
                        input = input.Substring(2);
                    }

                    return UInt16.Parse(input, System.Globalization.NumberStyles.HexNumber, culture);
                }
                else
                {
                    return base.ConvertFrom(context, culture, value);
                }
            }
        }
        class NKMObjectEditor : UITypeEditor
        {
            public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
            {
                return UITypeEditorEditStyle.Modal;
            }
            public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                IWindowsFormsEditorService svc = (IWindowsFormsEditorService)
                    provider.GetService(typeof(IWindowsFormsEditorService));
                if (svc != null)
                {
                    svc.ShowDialog(new MKDS_Course_Editor.NKM.NKMObjectEditor());
                    // update etc 
                }
                return value;
            }
        } 

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices.Count != 0)
            {
                item = null;
                Form f = new obji_edit(m.OBJI.Items[listView1.SelectedIndices[0]]);
                f.ShowDialog();
                if (item != null)
                {
                    int index = listView1.SelectedIndices[0];
                    m.OBJI.Items[index] = (OBJi)item;
                    ListViewItem n = new ListViewItem((listView1.SelectedIndices[0] + 1).ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].TransX.ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].TransY.ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].TransZ.ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].RotX.ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].RotY.ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].RotZ.ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].ScaleX.ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].ScaleY.ToString());
                    n.SubItems.Add(m.OBJI.Items[listView1.SelectedIndices[0]].ScaleZ.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[listView1.SelectedIndices[0]].ObjectID).Replace("-", "") + System.BitConverter.ToString(m.OBJI.Items[listView1.SelectedIndices[0]].RouteID).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[listView1.SelectedIndices[0]].Setting1).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[listView1.SelectedIndices[0]].Setting2).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[listView1.SelectedIndices[0]].Setting3).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[listView1.SelectedIndices[0]].Setting4).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.OBJI.Items[listView1.SelectedIndices[0]].Setting5).Replace("-", ""));
                    
                    //chart1.Series[0].Points[listView1.SelectedIndices[0]].XValue = Convert.ToDouble(item.SubItems[1].Text);
                    //chart1.Series[0].Points[listView1.SelectedIndices[0]].YValues[0] = Convert.ToDouble(item.SubItems[3].Text);
                    nkmEditorControl1.OBJI[index].X = m.OBJI.Items[index].TransX;
                    nkmEditorControl1.OBJI[index].Y = m.OBJI.Items[index].TransY;
                    nkmEditorControl1.OBJI[index].Z = m.OBJI.Items[index].TransZ;
                    nkmEditorControl1.OBJI[index].Angle = m.OBJI.Items[index].RotY;
                    if (Properties.Resources.ResourceManager.GetObject("OBJ_" + BitConverter.ToString(m.OBJI.Items[index].ObjectID).Replace("-", "") + ((m.OBJI.Items[index].ObjectID[0] == 0x6D && m.OBJI.Items[index].ObjectID[1] == 0x00) == false ? "" : "_" + BitConverter.ToInt32(m.OBJI.Items[index].Setting1, 0))) != null)
                    {
                        nkmEditorControl1.OBJI[index].MarkerImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("OBJ_" + BitConverter.ToString(m.OBJI.Items[index].ObjectID).Replace("-", "") + ((m.OBJI.Items[index].ObjectID[0] == 0x6D && m.OBJI.Items[index].ObjectID[1] == 0x00) == false ? "" : "_" + BitConverter.ToInt32(m.OBJI.Items[index].Setting1, 0)));
                    }
                    else
                    {
                        //chart1.Series[0].Points[j].MarkerColor = Color.Red;
                        //nkmEditorControl1.OBJI.Add(m.OBJI.Items[j].TransX, m.OBJI.Items[j].TransY, m.OBJI.Items[j].TransZ, m.OBJI.Items[j].RotY);
                        nkmEditorControl1.OBJI[index].MarkerImage = null;
                    }
                    listView1.Items[index] = n;
                }
            }
        }

        private void nkm_Shown(object sender, EventArgs e)
        {

        }

        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            /*File.Copy(path_, path_ + ".bak", true);
            EndianBinaryWriter bw = new EndianBinaryWriter(File.Open(path_, FileMode.Create), Endianness.LittleEndian);
            //header
            bw.Write("NKMD", Encoding.ASCII, false);
            bw.Write(new byte[] { 0x25, 0x00, 0x4C, 0x00 }, 0, 4);
            bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            int _1;
            if (listView1.Items.Count == 0)
            {
                _1 = 8;
            }
            else
            {
                _1 = (listView1.Items.Count * 60) + 8;
            }
            int _2;
            if (listView2.Items.Count == 0)
            {
                _2 = _1 + 12;
            }
            else
            {
                _2 = _1 + (listView2.Items.Count * 4) + 8;
            }
            int _3;
            if (listView3.Items.Count == 0)
            {
                _3 = _2 + 12;
            }
            else
            {
                _3 = _2 + (listView3.Items.Count * 20) + 8;
            }
            int _4;
            if (listView4.Items.Count == 0)
            {
                _4 = _3 + 8;
            }
            else
            {
                _4 = _3 + stag.Length + 4;
            }
            int _5;
            if (listView5.Items.Count == 0)
            {
                _5 = _4 + 12;
            }
            else
            {
                _5 = _4 + (listView5.Items.Count * 28) + 8;
            }
            int _6;
            if (listView6.Items.Count == 0)
            {
                _6 = _5 + 12;
            }
            else
            {
                _6 = _5 + (listView6.Items.Count * 32) + 8;
            }
            int _7;
            if (listView7.Items.Count == 0)
            {
                _7 = _6 + 12;
            }
            else
            {
                _7 = _6 + (listView7.Items.Count * 28) + 8;
            }
            int _8;
            if (listView8.Items.Count == 0)
            {
                _8 = _7 + 8;
            }
            else
            {
                _8 = _7 + (listView8.Items.Count * 28) + 8;
            }
            int _9;
            if (listView9.Items.Count == 0)
            {
                _9 = _8 + 8;
            }
            else
            {
                _9 = _8 + (listView9.Items.Count * 28) + 8;
            }
            int _10;
            if (listView10.Items.Count == 0)
            {
                _10 = _9 + 12;
            }
            else
            {
                _10 = _9 + (listView10.Items.Count * 36) + 8;
            }
            int _11;
            if (listView11.Items.Count == 0)
            {
                _11 = _10 + 12;
            }
            else
            {
                _11 = _10 + (listView11.Items.Count * 12) + 8;
            }
            int _12;
            if (listView12.Items.Count == 0)
            {
                _12 = _11 + 12;
            }
            else
            {
                _12 = _11 + (listView12.Items.Count * 20) + 8;
            }
            int _13;
            if (listView13.Items.Count == 0)
            {
                _13 = _12 + 12;
            }
            else
            {
                _13 = _12 + (listView13.Items.Count * 12) + 8;
            }
            int _14;
            int _15;
            if (EPOI == "EPOI")
            {
                if (listView14.Items.Count == 0)
                {
                    _14 = _13 + 12;
                }
                else
                {
                    _14 = _13 + (listView14.Items.Count * 24) + 8;
                }
                if (listView15.Items.Count == 0)
                {
                    _15 = _14 + 12;
                }
                else
                {
                    _15 = _14 + (listView15.Items.Count * 12) + 8;
                }
            }
            else
            {
                if (listView16.Items.Count == 0)
                {
                    _14 = _13 + 12;
                }
                else
                {
                    _14 = _13 + (listView16.Items.Count * 24) + 8;
                }
                if (listView17.Items.Count == 0)
                {
                    _15 = _14 + 12;
                }
                else
                {
                    _15 = _14 + (listView17.Items.Count * 20) + 8;
                }
            }
            int _16;
            if (listView18.Items.Count == 0)
            {
                _16 = _15 + 12;
            }
            else
            {
                _16 = _15 + (listView18.Items.Count * 72) + 8;
            }
            bw.Write(inttobyte(_1), 0, 4);
            bw.Write(inttobyte(_2), 0, 4);
            bw.Write(inttobyte(_3), 0, 4);
            bw.Write(inttobyte(_4), 0, 4);
            bw.Write(inttobyte(_5), 0, 4);
            bw.Write(inttobyte(_6), 0, 4);
            bw.Write(inttobyte(_7), 0, 4);
            bw.Write(inttobyte(_8), 0, 4);
            bw.Write(inttobyte(_9), 0, 4);
            bw.Write(inttobyte(_10), 0, 4);
            bw.Write(inttobyte(_11), 0, 4);
            bw.Write(inttobyte(_12), 0, 4);
            bw.Write(inttobyte(_13), 0, 4);
            bw.Write(inttobyte(_14), 0, 4);
            bw.Write(inttobyte(_15), 0, 4);
            bw.Write(inttobyte(_16), 0, 4);
            //obji
            bw.Write("OBJI", Encoding.ASCII, false);
            bw.Write(inttobyte(listView1.Items.Count), 0, 4);
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[5].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[6].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[7].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[8].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView1.Items[i].SubItems[9].Text))), 0, 4);
                bw.Write(stringtobyte(listView1.Items[i].SubItems[10].Text), 0, 4);
                bw.Write(stringtobyte(listView1.Items[i].SubItems[11].Text), 0, 4);
                bw.Write(stringtobyte(listView1.Items[i].SubItems[12].Text), 0, 4);
                bw.Write(stringtobyte(listView1.Items[i].SubItems[13].Text), 0, 4);
                bw.Write(stringtobyte(listView1.Items[i].SubItems[14].Text), 0, 4);
                bw.Write(stringtobyte(listView1.Items[i].SubItems[15].Text), 0, 4);
            }
            //path
            bw.Write("PATH", Encoding.ASCII, false);
            bw.Write(inttobyte(listView2.Items.Count), 0, 4); ;
            for (int i = 0; i < listView2.Items.Count; i++)
            {
                bw.Write(stringtobyte(listView2.Items[i].SubItems[1].Text), 0, 4);
            }
            if (listView2.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            //poit
            bw.Write("POIT", Encoding.ASCII, false);
            bw.Write(inttobyte(listView3.Items.Count), 0, 4);
            for (int i = 0; i < listView3.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView3.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView3.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView3.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView3.Items[i].SubItems[4].Text) / 4096)), 0, 4);
                bw.Write(stringtobyte(listView3.Items[i].SubItems[5].Text), 0, 4);
            }
            if (listView3.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            //stag
            bw.Write("STAG", Encoding.ASCII, false);
            bw.Write(stag, 0, stag.Length);
            //ktps
            bw.Write("KTPS", Encoding.ASCII, false);
            bw.Write(inttobyte(listView5.Items.Count), 0, 4);
            for (int i = 0; i < listView5.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView5.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView5.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView5.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView5.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView5.Items[i].SubItems[5].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView5.Items[i].SubItems[6].Text))), 0, 4);
                bw.Write(stringtobyte(listView5.Items[i].SubItems[7].Text), 0, 4);
            }
            //ktpj
            bw.Write("KTPJ", Encoding.ASCII, false);
            bw.Write(inttobyte(listView6.Items.Count), 0, 4);
            for (int i = 0; i < listView6.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView6.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView6.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView6.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView6.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView6.Items[i].SubItems[5].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView6.Items[i].SubItems[6].Text))), 0, 4);
                bw.Write(stringtobyte(listView6.Items[i].SubItems[7].Text), 0, 4);
                if (listView6.Items[i].SubItems.Count == 9)
                {
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView6.Items[i].SubItems[8].Text) / 4096)), 0, 4);
                }
                else
                {
                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
                }
            }
            if (listView6.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            //ktp2
            bw.Write("KTP2", Encoding.ASCII, false);
            bw.Write(inttobyte(listView7.Items.Count), 0, 4);
            for (int i = 0; i < listView7.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView7.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView7.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView7.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView7.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView7.Items[i].SubItems[5].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView7.Items[i].SubItems[6].Text))), 0, 4);
                bw.Write(stringtobyte(listView7.Items[i].SubItems[7].Text), 0, 4);
            }
            //ktpc
            bw.Write("KTPC", Encoding.ASCII, false);
            bw.Write(inttobyte(listView8.Items.Count), 0, 4);
            for (int i = 0; i < listView8.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView8.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView8.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView8.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView8.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView8.Items[i].SubItems[5].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView8.Items[i].SubItems[6].Text))), 0, 4);
                bw.Write(stringtobyte(listView8.Items[i].SubItems[7].Text), 0, 4);
            }
            //ktpm
            bw.Write("KTPM", Encoding.ASCII, false);
            bw.Write(inttobyte(listView9.Items.Count), 0, 4);
            for (int i = 0; i < listView9.Items.Count; i++)
            {
                bw.Write(stringtobyte(listView9.Items[i].SubItems[1].Text), 0, 4);
                bw.Write(stringtobyte(listView9.Items[i].SubItems[2].Text), 0, 4);
                bw.Write(stringtobyte(listView9.Items[i].SubItems[3].Text), 0, 4);
                bw.Write(stringtobyte(listView9.Items[i].SubItems[4].Text), 0, 4);
                bw.Write(stringtobyte(listView9.Items[i].SubItems[5].Text), 0, 4);
                bw.Write(stringtobyte(listView9.Items[i].SubItems[6].Text), 0, 4);
                bw.Write(stringtobyte(listView9.Items[i].SubItems[7].Text), 0, 4);
            }
            //cpoi
            bw.Write("CPOI", Encoding.ASCII, false);
            bw.Write(inttobyte(listView10.Items.Count), 0, 4);
            for (int i = 0; i < listView10.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView10.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView10.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView10.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView10.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(listView10.Items[i].SubItems[5].Text), 0, 4);
                bw.Write(stringtobyte(listView10.Items[i].SubItems[6].Text), 0, 4);
                bw.Write(stringtobyte(listView10.Items[i].SubItems[7].Text), 0, 4);
                bw.Write(stringtobyte(listView10.Items[i].SubItems[8].Text), 0, 4);
                bw.Write(stringtobyte(listView10.Items[i].SubItems[9].Text), 0, 4);
            }
            if (listView10.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            //cpat
            bw.Write("CPAT", Encoding.ASCII, false);
            bw.Write(inttobyte(listView11.Items.Count), 0, 4);
            for (int i = 0; i < listView11.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView11.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(listView11.Items[i].SubItems[2].Text), 0, 4);
                bw.Write(stringtobyte(listView11.Items[i].SubItems[3].Text), 0, 4);
            }
            if (listView11.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            //ipoi
            bw.Write("IPOI", Encoding.ASCII, false);
            bw.Write(inttobyte(listView12.Items.Count), 0, 4);
            for (int i = 0; i < listView12.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView12.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView12.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView12.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView12.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(listView12.Items[i].SubItems[5].Text), 0, 4);
            }
            if (listView12.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            //ipat
            bw.Write("IPAT", Encoding.ASCII, false);
            bw.Write(inttobyte(listView13.Items.Count), 0, 4);
            for (int i = 0; i < listView13.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView13.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(listView13.Items[i].SubItems[2].Text), 0, 4);
                bw.Write(stringtobyte(listView13.Items[i].SubItems[3].Text), 0, 4);
            }
            if (listView13.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            if (EPOI == "EPOI")
            {
                //epoi
                bw.Write("EPOI", Encoding.ASCII, false);
                bw.Write(inttobyte(listView14.Items.Count), 0, 4);
                for (int i = 0; i < listView14.Items.Count; i++)
                {
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView14.Items[i].SubItems[1].Text))), 0, 4);
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView14.Items[i].SubItems[2].Text))), 0, 4);
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView14.Items[i].SubItems[3].Text))), 0, 4);
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView14.Items[i].SubItems[4].Text))), 0, 4);
                    bw.Write(stringtobyte(listView14.Items[i].SubItems[5].Text), 0, 4);
                    bw.Write(stringtobyte(listView14.Items[i].SubItems[6].Text), 0, 4);
                }
                if (listView14.Items.Count == 0)
                {
                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
                }
                //epat
                bw.Write("EPAT", Encoding.ASCII, false);
                bw.Write(inttobyte(listView15.Items.Count), 0, 4);
                for (int i = 0; i < listView15.Items.Count; i++)
                {
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView15.Items[i].SubItems[1].Text))), 0, 4);
                    bw.Write(stringtobyte(listView15.Items[i].SubItems[2].Text), 0, 4);
                    bw.Write(stringtobyte(listView15.Items[i].SubItems[3].Text), 0, 4);
                }
                if (listView15.Items.Count == 0)
                {
                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
                }
            }
            else
            {
                //mepo
                bw.Write("MEPO", Encoding.ASCII, false);
                bw.Write(inttobyte(listView16.Items.Count), 0, 4);
                for (int i = 0; i < listView16.Items.Count; i++)
                {
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView16.Items[i].SubItems[1].Text))), 0, 4);
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView16.Items[i].SubItems[2].Text))), 0, 4);
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView16.Items[i].SubItems[3].Text))), 0, 4);
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView16.Items[i].SubItems[4].Text))), 0, 4);
                    bw.Write(stringtobyte(listView16.Items[i].SubItems[5].Text), 0, 4);
                    bw.Write(stringtobyte(listView16.Items[i].SubItems[6].Text), 0, 4);
                }
                if (listView16.Items.Count == 0)
                {
                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
                }
                //mepa
                bw.Write("MEPA", Encoding.ASCII, false);
                bw.Write(inttobyte(listView17.Items.Count), 0, 4);
                for (int i = 0; i < listView17.Items.Count; i++)
                {
                    bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView17.Items[i].SubItems[1].Text))), 0, 4);
                    bw.Write(stringtobyte(listView17.Items[i].SubItems[2].Text), 0, 4);
                    bw.Write(stringtobyte(listView17.Items[i].SubItems[3].Text), 0, 4);
                    bw.Write(stringtobyte(listView17.Items[i].SubItems[4].Text), 0, 4);
                    bw.Write(stringtobyte(listView17.Items[i].SubItems[5].Text), 0, 4);
                }
                if (listView17.Items.Count == 0)
                {
                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
                }
            }
            //area
            bw.Write("AREA", Encoding.ASCII, false);
            bw.Write(inttobyte(listView18.Items.Count), 0, 4);
            for (int i = 0; i < listView18.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView18.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView18.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView18.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView18.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView18.Items[i].SubItems[5].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView18.Items[i].SubItems[6].Text))), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[7].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[8].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[9].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[10].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[11].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[12].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[13].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[14].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[15].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[16].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[17].Text), 0, 4);
                bw.Write(stringtobyte(listView18.Items[i].SubItems[18].Text), 0, 4);
            }
            if (listView18.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            //came
            bw.Write("CAME", Encoding.ASCII, false);
            bw.Write(inttobyte(listView19.Items.Count), 0, 4);
            for (int i = 0; i < listView19.Items.Count; i++)
            {
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[1].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[2].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[3].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[4].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[5].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[6].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[7].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[8].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[9].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[10].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[11].Text))), 0, 4);
                bw.Write(stringtobyte(HexConverter(Convert.ToDouble(listView19.Items[i].SubItems[12].Text))), 0, 4);
                bw.Write(stringtobyte(listView19.Items[i].SubItems[13].Text), 0, 4);
                bw.Write(stringtobyte(listView19.Items[i].SubItems[14].Text), 0, 4);
                bw.Write(stringtobyte(listView19.Items[i].SubItems[15].Text), 0, 4);
                bw.Write(stringtobyte(listView19.Items[i].SubItems[16].Text), 0, 4);
                bw.Write(stringtobyte(listView19.Items[i].SubItems[17].Text), 0, 4);
                bw.Write(stringtobyte(listView19.Items[i].SubItems[18].Text), 0, 4);
                bw.Write(stringtobyte(listView19.Items[i].SubItems[19].Text), 0, 4);
            }
            if (listView19.Items.Count == 0)
            {
                bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4);
            }
            bw.Close();*/
            Save();
        }
        void Save()
        {
            EndianBinaryWriter er = new EndianBinaryWriter(File.OpenWrite(path_), Endianness.LittleEndian);
            er.Write("NKMD", Encoding.ASCII, false);
            er.Write((Int16)0x25);
            er.Write((Int16)0x4C);
            for (int i = 0; i < 17; i++)
            {
                er.Write((Int32)0);
            }
            //OBJI - Object Information
            er.Write("OBJI", Encoding.ASCII, false);
            er.Write((Int32)m.OBJI.Items.Count);
            for (int i = 0; i < m.OBJI.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].TransX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].TransY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].TransZ))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].RotX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].RotY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].RotZ))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].ScaleX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].ScaleY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.OBJI.Items[i].ScaleZ))), 0, 4);
                er.Write(m.OBJI.Items[i].ObjectID, 0, 2);
                er.Write(m.OBJI.Items[i].RouteID, 0, 2);
                er.Write(m.OBJI.Items[i].Setting1, 0, 4);
                er.Write(m.OBJI.Items[i].Setting2, 0, 4);
                er.Write(m.OBJI.Items[i].Setting3, 0, 4);
                er.Write(m.OBJI.Items[i].Setting4, 0, 4);
                er.Write(m.OBJI.Items[i].Setting5, 0, 4);
            }
            long offset = er.BaseStream.Position;
            er.BaseStream.Position = 0xC;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //PATH - Paths
            er.Write("PATH", Encoding.ASCII, false);
            er.Write((Int32)m.PATH.Items.Count);
            for (int i = 0; i < m.PATH.Items.Count; i++)
            {
                er.Write(m.PATH.Items[i].NrPoit, 0, 4);
            }
            if (m.PATH.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x10;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //POIT - Points
            er.Write("POIT", Encoding.ASCII, false);
            er.Write((Int32)m.POIT.Items.Count);
            for (int i = 0; i < m.POIT.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.POIT.Items[i].X))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.POIT.Items[i].Y))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.POIT.Items[i].Z))), 0, 4);
                er.Write((byte)m.POIT.Items[i].Nr);
                er.Write(m.POIT.Items[i].Setting1, 0, 3);
                er.Write(m.POIT.Items[i].Setting2, 0, 4);
            }
            if (m.POIT.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x14;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //STAG - Start and G...
            er.Write("STAG", Encoding.ASCII, false);
            er.Write((Int16)m.STAG.NrItem);
            er.Write((Int16)m.STAG.nrLap);
            er.Write(m.STAG.data, 0, m.STAG.data.Length);
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x18;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //KTPS - Kart Position Start
            er.Write("KTPS", Encoding.ASCII, false);
            er.Write((Int32)m.KTPS.Items.Count);
            for (int i = 0; i < m.KTPS.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPS.Items[i].TransX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPS.Items[i].TransY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPS.Items[i].TransZ))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPS.Items[i].RotateX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPS.Items[i].RotateY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPS.Items[i].RotateZ))), 0, 4);
                er.Write(m.KTPS.Items[i].Setting1, 0, 4);
            }
            if (m.KTPS.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x1C;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //KTPJ - Kart Position Jugemu
            er.Write("KTPJ", Encoding.ASCII, false);
            er.Write((Int32)m.KTPJ.Items.Count);
            for (int i = 0; i < m.KTPJ.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPJ.Items[i].TransX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPJ.Items[i].TransY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPJ.Items[i].TransZ))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPJ.Items[i].RotateX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPJ.Items[i].RotateY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPJ.Items[i].RotateZ))), 0, 4);
                er.Write(m.KTPJ.Items[i].Setting1, 0, 4);
                er.Write(m.KTPJ.Items[i].Setting2, 0, 4);
            }
            if (m.KTPJ.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x20;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //KTP2 - Kart Position 2
            er.Write("KTP2", Encoding.ASCII, false);
            er.Write((Int32)m.KTP2.Items.Count);
            for (int i = 0; i < m.KTP2.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTP2.Items[i].TransX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTP2.Items[i].TransY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTP2.Items[i].TransZ))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTP2.Items[i].RotateX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTP2.Items[i].RotateY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTP2.Items[i].RotateZ))), 0, 4);
                er.Write(m.KTP2.Items[i].Setting1, 0, 4);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x24;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //KTPC - Kart Position Cannon
            er.Write("KTPC", Encoding.ASCII, false);
            er.Write((Int32)m.KTPC.Items.Count);
            for (int i = 0; i < m.KTPC.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPC.Items[i].TransX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPC.Items[i].TransY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPC.Items[i].TransZ))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPC.Items[i].RotateX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPC.Items[i].RotateY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPC.Items[i].RotateZ))), 0, 4);
                er.Write(m.KTPC.Items[i].Setting1, 0, 4);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x28;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //KTPM - Kart Position Mission
            er.Write("KTPM", Encoding.ASCII, false);
            er.Write((Int32)m.KTPM.Items.Count);
            for (int i = 0; i < m.KTPM.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPM.Items[i].TransX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPM.Items[i].TransY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPM.Items[i].TransZ))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPM.Items[i].RotateX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPM.Items[i].RotateY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.KTPM.Items[i].RotateZ))), 0, 4);
                er.Write(m.KTPM.Items[i].Setting1, 0, 4);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x2C;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //CPOI - Check Points
            er.Write("CPOI", Encoding.ASCII, false);
            er.Write((Int32)m.CPOI.Items.Count);
            for (int i = 0; i < m.CPOI.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CPOI.Items[i].X1))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CPOI.Items[i].Y1))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CPOI.Items[i].X2))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CPOI.Items[i].Y2))), 0, 4);
                er.Write(m.CPOI.Items[i].Setting1, 0, 4);
                er.Write(m.CPOI.Items[i].Setting2, 0, 4);
                er.Write(m.CPOI.Items[i].Setting3, 0, 4);
                er.Write(m.CPOI.Items[i].SData, 0, 4);
                er.Write(m.CPOI.Items[i].LRespawn, 0, 4);
            }
            if (m.CPOI.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x30;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //CPAT - Check Paths
            er.Write("CPAT", Encoding.ASCII, false);
            er.Write((Int32)m.CPAT.Items.Count);
            for (int i = 0; i < m.CPAT.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CPAT.Items[i].Setting1))), 0, 4);
                er.Write(m.CPAT.Items[i].Setting2, 0, 4);
                er.Write(m.CPAT.Items[i].Setting3, 0, 4);
            }
            if (m.CPAT.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x34;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //IPOI - Item Points
            er.Write("IPOI", Encoding.ASCII, false);
            er.Write((Int32)m.IPOI.Items.Count);
            for (int i = 0; i < m.IPOI.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.IPOI.Items[i].X))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.IPOI.Items[i].Y))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.IPOI.Items[i].Z))), 0, 4);
                er.Write(m.IPOI.Items[i].Setting1, 0, 4);
                er.Write(m.IPOI.Items[i].Setting2, 0, 4);
            }
            if (m.IPOI.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x38;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //IPAT - Item Paths
            er.Write("IPAT", Encoding.ASCII, false);
            er.Write((Int32)m.IPAT.Items.Count);
            for (int i = 0; i < m.IPAT.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.IPAT.Items[i].Setting1))), 0, 4);
                er.Write(m.IPAT.Items[i].Setting2, 0, 4);
                er.Write(m.IPAT.Items[i].Setting3, 0, 4);
            }
            if (m.IPAT.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x3C;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            if (m.MEPO.ID != "MEPO")
            {
                //EPOI - Enemy Points
                er.Write("EPOI", Encoding.ASCII, false);
                er.Write((Int32)m.EPOI.Items.Count);
                for (int i = 0; i < m.EPOI.Items.Count; i++)
                {
                    er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.EPOI.Items[i].X))), 0, 4);
                    er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.EPOI.Items[i].Y))), 0, 4);
                    er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.EPOI.Items[i].Z))), 0, 4);
                    er.Write(m.EPOI.Items[i].Setting1, 0, 4);
                    er.Write(m.EPOI.Items[i].Setting2, 0, 4);
                    er.Write(m.EPOI.Items[i].Setting3, 0, 4);
                }
                if (m.EPOI.Items.Count == 0)
                {
                    er.Write((Int32)0);
                }
                offset = er.BaseStream.Position;
                er.BaseStream.Position = 0x40;
                er.Write((Int32)offset - 0x4C);
                er.BaseStream.Position = offset;
                //EPAT - Enemy Paths
                er.Write("EPAT", Encoding.ASCII, false);
                er.Write((Int32)m.EPAT.Items.Count);
                for (int i = 0; i < m.EPAT.Items.Count; i++)
                {
                    er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.EPAT.Items[i].Setting1))), 0, 4);
                    er.Write(m.EPAT.Items[i].Setting2, 0, 4);
                    er.Write(m.EPAT.Items[i].Setting3, 0, 4);
                }
                if (m.EPAT.Items.Count == 0)
                {
                    er.Write((Int32)0);
                }
                offset = er.BaseStream.Position;
                er.BaseStream.Position = 0x44;
                er.Write((Int32)offset - 0x4C);
                er.BaseStream.Position = offset;
            }
            else
            {
                //MEPO - Mini(From MiniGames) Enemy Points
                er.Write("MEPO", Encoding.ASCII, false);
                er.Write((Int32)m.MEPO.Items.Count);
                for (int i = 0; i < m.MEPO.Items.Count; i++)
                {
                    er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.MEPO.Items[i].X))), 0, 4);
                    er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.MEPO.Items[i].Y))), 0, 4);
                    er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.MEPO.Items[i].Z))), 0, 4);
                    er.Write(m.MEPO.Items[i].Setting1, 0, 4);
                    er.Write(m.MEPO.Items[i].Setting2, 0, 4);
                    er.Write(m.MEPO.Items[i].Setting3, 0, 4);
                }
                if (m.MEPO.Items.Count == 0)
                {
                    er.Write((Int32)0);
                }
                offset = er.BaseStream.Position;
                er.BaseStream.Position = 0x40;
                er.Write((Int32)offset - 0x4C);
                er.BaseStream.Position = offset;
                //MEPA - Mini(From MiniGames) Enemy Paths
                er.Write("MEPA", Encoding.ASCII, false);
                er.Write((Int32)m.MEPA.Items.Count);
                for (int i = 0; i < m.MEPA.Items.Count; i++)
                {
                    er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.MEPA.Items[i].Setting1))), 0, 4);
                    er.Write(m.MEPA.Items[i].Setting2, 0, 4);
                    er.Write(m.MEPA.Items[i].Setting3, 0, 4);
                    er.Write(m.MEPA.Items[i].Setting4, 0, 4);
                    er.Write(m.MEPA.Items[i].Setting5, 0, 4);
                }
                if (m.MEPA.Items.Count == 0)
                {
                    er.Write((Int32)0);
                }
                offset = er.BaseStream.Position;
                er.BaseStream.Position = 0x44;
                er.Write((Int32)offset - 0x4C);
                er.BaseStream.Position = offset;
            }
            //AREA - Areas
            er.Write("AREA", Encoding.ASCII, false);
            er.Write((Int32)m.AREA.Items.Count);
            for (int i = 0; i < m.AREA.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.AREA.Items[i].TransX))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.AREA.Items[i].TransY))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.AREA.Items[i].TransZ))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.AREA.Items[i].Setting1))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.AREA.Items[i].Setting2))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.AREA.Items[i].Setting3))), 0, 4);
                er.Write(m.AREA.Items[i].Setting4, 0, 4);
                er.Write(m.AREA.Items[i].Setting5, 0, 4);
                er.Write(m.AREA.Items[i].Setting6, 0, 4);
                er.Write(m.AREA.Items[i].Setting7, 0, 4);
                er.Write(m.AREA.Items[i].Setting8, 0, 4);
                er.Write(m.AREA.Items[i].Setting9, 0, 4);
                er.Write(m.AREA.Items[i].Setting10, 0, 4);
                er.Write(m.AREA.Items[i].Setting11, 0, 4);
                er.Write(m.AREA.Items[i].Setting12, 0, 4);
                er.Write(m.AREA.Items[i].Setting13, 0, 4);
                er.Write(m.AREA.Items[i].Setting14, 0, 4);
                er.Write(m.AREA.Items[i].Setting15, 0, 4);
            }
            if (m.AREA.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            offset = er.BaseStream.Position;
            er.BaseStream.Position = 0x48;
            er.Write((Int32)offset - 0x4C);
            er.BaseStream.Position = offset;
            //CAME - Cameras
            er.Write("CAME", Encoding.ASCII, false);
            er.Write((Int32)m.CAME.Items.Count);
            for (int i = 0; i < m.CAME.Items.Count; i++)
            {
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].X1))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Y1))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Z1))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Zero1))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Zero2))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Zero3))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].X2))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Y2))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Z2))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].X3))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Y3))), 0, 4);
                er.Write(stringtobyte(HexConverter(Convert.ToDouble(m.CAME.Items[i].Z3))), 0, 4);
                er.Write(m.CAME.Items[i].Setting1, 0, 4);
                er.Write(m.CAME.Items[i].Setting2, 0, 4);
                er.Write(m.CAME.Items[i].Setting3, 0, 4);
                er.Write(m.CAME.Items[i].Setting4, 0, 4);
                er.Write(m.CAME.Items[i].Setting5, 0, 4);
                er.Write(m.CAME.Items[i].Setting6, 0, 4);
                er.Write(m.CAME.Items[i].Setting7, 0, 4);
            }
            if (m.CAME.Items.Count == 0)
            {
                er.Write((Int32)0);
            }
            er.Close();
        }
        byte[] doubletobyte(double a)
        {
            byte[] buffer;
            Int64 i = System.BitConverter.DoubleToInt64Bits(a);
            buffer = System.BitConverter.GetBytes(i);
            return buffer;
        }
        byte[] inttobyte(int a)
        {
            byte[] buffer;
            buffer = System.BitConverter.GetBytes(a);
            return buffer;
        }
        public static byte[] stringtobyte(string a)
        {
            byte[] buffer;
            int discarded;
            buffer = HexEncoding.GetBytes(a, out discarded);
            return buffer;
        }
        internal static string DoubleToHex(double value, int maxDecimals)
        {
            string result = string.Empty;
            if (value < 0)
            {
                result += "-";
                value = -value;
            }
            if (value > ulong.MaxValue)
            {
                result += double.PositiveInfinity.ToString();
                return result;
            }
            ulong trunc = (ulong)value;
            result += trunc.ToString("X");
            value -= trunc;
            if (value == 0)
            {
                return result;
            }
            result += ".";
            byte hexdigit;
            while ((value != 0) && (maxDecimals != 0))
            {
                value *= 16;
                hexdigit = (byte)value;
                result += hexdigit.ToString("X");
                value -= hexdigit;
                maxDecimals--;
            }
            return result;
        }

        internal static ulong HexToUInt64(string hex)
        {
            ulong result;
            if (ulong.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result))
            {
                return result;
            }
            throw new ArgumentException("Cannot parse hex string.", "hex");
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices.Count != 0)
            {

            }
        }


        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            listView1.SetSortIcon(10, SortOrder.Ascending);
        }

        private void listView19_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView19.SelectedIndices.Count == 0)
            {
                toolStripButton7.Enabled = false;
                toolStripButton8.Enabled = false;
                toolStripButton9.Enabled = false;
                toolStripButton10.Enabled = false;
                toolStripButton19.Enabled = false;
            }
            else
            {
                toolStripButton7.Enabled = true;
                toolStripButton8.Enabled = true;
                toolStripButton9.Enabled = true;
                toolStripButton10.Enabled = true;
                toolStripButton19.Enabled = true;
            }
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            ListViewItem t = new ListViewItem((listView19.Items.Count+1).ToString());
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0F002404");
            t.SubItems.Add("740F0F00");
            t.SubItems.Add("2404740f");
            t.SubItems.Add("00000300");
            t.SubItems.Add("00000000");
            t.SubItems.Add("28006400");
            t.SubItems.Add("00000000");
            listView19.Items.Add(t);
            //chart1.Series[10].Points.AddXY(0, 0);
            //chart1.Series[10].Points.AddXY(0, 0);
            //chart1.Series[10].Points.AddXY(0, 0);
            //chart1.Series[10].Points[chart1.Series[0].Points.Count - 1].Color = Color.Transparent;
            CAMe o = new CAMe();
            o.X1 = 0;
            o.Y1 = 0;
            o.Z1 = 0;
            o.Zero1 = 0;
            o.Zero2 = 0;
            o.Zero3 = 0;
            o.X2 = 0;
            o.Y2 = 0;
            o.Z2 = 0;
            o.X3 = 0;
            o.Y3 = 0;
            o.Z3 = 0;
            o.Setting1 = stringtobyte("0F002404");
            o.Setting2 = stringtobyte("740F0F00");
            o.Setting3 = stringtobyte("2404740f");
            o.Setting4 = stringtobyte("00000300");
            o.Setting5 = stringtobyte("00000000");
            o.Setting6 = stringtobyte("28006400");
            o.Setting7 = stringtobyte("00000000"); ;
            m.CAME.Items.Add(o);
            nkmEditorControl1.CAME.Add(0, 0, 0,0,0,0,0,0,0);
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            if (listView19.SelectedIndices.Count != 0)
            {
                //chart1.Series[10].Points.RemoveAt(listView19.SelectedIndices[0] * 3);
                //chart1.Series[10].Points.RemoveAt(listView19.SelectedIndices[0] * 3);
                //chart1.Series[10].Points.RemoveAt(listView19.SelectedIndices[0] * 3);
                m.CAME.Items.RemoveAt(listView19.SelectedIndices[0]);
                nkmEditorControl1.CAME.RemoveAt(listView19.SelectedIndices[0]);
                listView19.Items.RemoveAt(listView19.SelectedIndices[0]);
            }
        }

        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            if (listView19.SelectedIndices.Count != 0)
            {
                item = null;
                Form f = new CAME(m.CAME.Items[listView19.SelectedIndices[0]]);
                f.ShowDialog();
                if (item != null)
                {
                    m.CAME.Items[listView19.SelectedIndices[0]] = (CAMe)item;
                    ListViewItem n = new ListViewItem((listView19.SelectedIndices[0] + 1).ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].X1.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Y1.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Z1.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Zero1.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Zero1.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Zero1.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].X2.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Y2.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Z2.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].X3.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Y3.ToString());
                    n.SubItems.Add(m.CAME.Items[listView19.SelectedIndices[0]].Z3.ToString());
                    n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[listView19.SelectedIndices[0]].Setting1).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[listView19.SelectedIndices[0]].Setting2).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[listView19.SelectedIndices[0]].Setting3).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[listView19.SelectedIndices[0]].Setting4).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[listView19.SelectedIndices[0]].Setting5).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[listView19.SelectedIndices[0]].Setting6).Replace("-", ""));
                    n.SubItems.Add(System.BitConverter.ToString(m.CAME.Items[listView19.SelectedIndices[0]].Setting7).Replace("-", ""));
                    
                    //chart1.Series[0].Points[listView1.SelectedIndices[0]].XValue = Convert.ToDouble(item.SubItems[1].Text);
                    //chart1.Series[0].Points[listView1.SelectedIndices[0]].YValues[0] = Convert.ToDouble(item.SubItems[3].Text);
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].X1 = m.OBJI.Items[listView19.SelectedIndices[0]].TransX;
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].Y1 = m.OBJI.Items[listView19.SelectedIndices[0]].TransY;
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].Z1 = m.OBJI.Items[listView19.SelectedIndices[0]].TransZ;
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].X2 = m.OBJI.Items[listView19.SelectedIndices[0]].TransX;
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].Y2 = m.OBJI.Items[listView19.SelectedIndices[0]].TransY;
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].Z2 = m.OBJI.Items[listView19.SelectedIndices[0]].TransZ;
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].X3 = m.OBJI.Items[listView19.SelectedIndices[0]].TransX;
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].Y3 = m.OBJI.Items[listView19.SelectedIndices[0]].TransY;
                    nkmEditorControl1.CAME[listView19.SelectedIndices[0]].Z3 = m.OBJI.Items[listView19.SelectedIndices[0]].TransZ;
                    listView19.Items[listView19.SelectedIndices[0]] = n;
                }
            }
        }

        private void toolStripButton9_Click(object sender, EventArgs e)
        {
            if (listView19.SelectedIndices.Count != 0 && listView19.SelectedItems[0].Index != 0)
            {
                CAMe d = m.CAME.Items[listView19.SelectedIndices[0]];
                m.CAME.Items.RemoveAt(listView19.SelectedIndices[0]);
                m.CAME.Items.Insert(listView19.SelectedIndices[0] - 1, d);
                MKDS_Course_Editor.NKM.NkmCamePoint p = nkmEditorControl1.CAME[listView19.SelectedIndices[0]];
                nkmEditorControl1.CAME.RemoveAt(listView19.SelectedIndices[0]);
                nkmEditorControl1.CAME.Insert(listView19.SelectedIndices[0] - 1, p);
                ListViewItem it = listView19.SelectedItems[0];
                int index = listView19.SelectedIndices[0];
                listView19.Items.RemoveAt(listView19.SelectedIndices[0]);
                listView19.Items.Insert(index - 1, it);
            }
        }

        private void toolStripButton10_Click(object sender, EventArgs e)
        {
            if (listView19.SelectedIndices.Count != 0 && listView19.SelectedItems[0].Index != listView19.Items.Count - 1)
            {
                CAMe d = m.CAME.Items[listView19.SelectedIndices[0]];
                m.CAME.Items.RemoveAt(listView19.SelectedIndices[0]);
                m.CAME.Items.Insert(listView19.SelectedIndices[0] + 1, d);
                MKDS_Course_Editor.NKM.NkmCamePoint p = nkmEditorControl1.CAME[listView19.SelectedIndices[0]];
                nkmEditorControl1.CAME.RemoveAt(listView19.SelectedIndices[0]);
                nkmEditorControl1.CAME.Insert(listView19.SelectedIndices[0] + 1, p);
                ListViewItem it = listView19.SelectedItems[0];
                int index = listView19.SelectedIndices[0];
                listView19.Items.RemoveAt(listView19.SelectedIndices[0]);
                listView19.Items.Insert(index + 1, it);
            }
        }

        private void toolStripButton11_Click(object sender, EventArgs e)
        {
            ListViewItem t = new ListViewItem(listView2.Items.Count.ToString());
            t.SubItems.Add("00000100");
            listView2.Items.Add(t);
            PATh p = new PATh();
            p.NrPoit = new byte[] { 0x00,0x00,0x01,0x00 };
            m.PATH.Items.Add(p);
        }

        private void toolStripButton12_Click(object sender, EventArgs e)
        {
            if (listView2.SelectedIndices.Count != 0)
            {
                m.PATH.Items.RemoveAt(listView2.SelectedIndices[0]);
                listView2.Items.RemoveAt(listView2.SelectedIndices[0]);
            }
        }

        private void listView2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView2.SelectedIndices.Count == 0)
            {
                toolStripButton12.Enabled = false;
                toolStripButton13.Enabled = false;
            }
            else
            {
                toolStripButton12.Enabled = true;
                toolStripButton13.Enabled = true;
            }
        }

        private void toolStripButton13_Click(object sender, EventArgs e)
        {
            if (listView2.SelectedIndices.Count != 0)
            {
                item = null;
                Form f = new PATH(m.PATH.Items[listView2.SelectedIndices[0]]);
                f.ShowDialog();
                if (item != null)
                {
                    m.PATH.Items[listView2.SelectedIndices[0]] = (PATh)item;
                    listView2.Items[listView2.SelectedIndices[0]].SubItems[1].Text = BitConverter.ToString(m.PATH.Items[listView2.SelectedIndices[0]].NrPoit).Replace("-","");
                }
            }
        }

        private void toolStripButton14_Click(object sender, EventArgs e)
        {
            ListViewItem t = new ListViewItem(listView3.Items.Count.ToString());
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("0");
            t.SubItems.Add("000000");
            t.SubItems.Add("00000000");
            listView3.Items.Add(t);
            POIt p = new POIt();
            p.X = 0;
            p.Y = 0;
            p.Z = 0;
            p.Nr = 0;
            p.Setting1 = new byte[3];
            p.Setting2 = new byte[4];
            m.POIT.Items.Add(p);
            nkmEditorControl1.POIT.Add(0, 0, 0, 0);
            //chart1.Series[1].Points.AddXY(0, 0);
        }

        private void toolStripButton15_Click(object sender, EventArgs e)
        {
            if (listView3.SelectedIndices.Count != 0)
            {
                nkmEditorControl1.POIT.RemoveAt(listView3.SelectedIndices[0]);
                m.POIT.Items.RemoveAt(listView3.SelectedIndices[0]);
                //chart1.Series[1].Points.RemoveAt(listView3.SelectedIndices[0]);
                listView3.Items.RemoveAt(listView3.SelectedIndices[0]);
            }
        }

        private void listView3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView3.SelectedIndices.Count == 0)
            {
                toolStripButton15.Enabled = false;
                toolStripButton16.Enabled = false;
                toolStripButton17.Enabled = false;
                toolStripButton18.Enabled = false;
            }
            else
            {
                toolStripButton15.Enabled = true;
                toolStripButton16.Enabled = true;
                toolStripButton17.Enabled = true;
                toolStripButton18.Enabled = true;
            }
        }

        private void toolStripButton16_Click(object sender, EventArgs e)
        {
            if (listView3.SelectedIndices.Count != 0)
            {
                item = null;
                Form f = new POIT(m.POIT.Items[listView3.SelectedIndices[0]]);
                f.ShowDialog();
                if (item != null)
                {
                    m.POIT.Items[listView3.SelectedIndices[0]] = (POIt)item;
                    ListViewItem t = new ListViewItem((listView3.SelectedIndices[0]+1).ToString());
                    t.SubItems.Add(m.POIT.Items[listView3.SelectedIndices[0]].X.ToString());
                    t.SubItems.Add(m.POIT.Items[listView3.SelectedIndices[0]].Y.ToString());
                    t.SubItems.Add(m.POIT.Items[listView3.SelectedIndices[0]].Z.ToString());
                    t.SubItems.Add(m.POIT.Items[listView3.SelectedIndices[0]].Nr.ToString());
                    t.SubItems.Add(BitConverter.ToString(m.POIT.Items[listView3.SelectedIndices[0]].Setting1).Replace("-",""));
                    t.SubItems.Add(BitConverter.ToString(m.POIT.Items[listView3.SelectedIndices[0]].Setting2).Replace("-", ""));
                    nkmEditorControl1.POIT[listView3.SelectedIndices[0]].X = m.POIT.Items[listView3.SelectedIndices[0]].X;
                    nkmEditorControl1.POIT[listView3.SelectedIndices[0]].Y = m.POIT.Items[listView3.SelectedIndices[0]].Y;
                    nkmEditorControl1.POIT[listView3.SelectedIndices[0]].Z = m.POIT.Items[listView3.SelectedIndices[0]].Z;
                    nkmEditorControl1.POIT[listView3.SelectedIndices[0]].Nr = m.POIT.Items[listView3.SelectedIndices[0]].Nr;
                    listView3.Items[listView3.SelectedIndices[0]] = t;
                    //chart1.Series[1].Points[item.Index].XValue = Convert.ToDouble(item.SubItems[1].Text);
                    //chart1.Series[1].Points[item.Index].YValues[0] = Convert.ToDouble(item.SubItems[3].Text);
                }
            }
        }

        private void toolStripButton19_Click(object sender, EventArgs e)
        {
            if (File.Exists(path_.Replace(Path.GetFileName(path_), "course_model.nsbmd")))
            {
                int num = 0;
                string one = listView19.SelectedItems[0].SubItems[17].Text.Remove(2);
                string two = listView19.SelectedItems[0].SubItems[17].Text.Remove(0, 2).Remove(2);
                for (int i = 0; i < int.Parse(two + one, NumberStyles.HexNumber); i++)
                {
                    string one1 = listView2.Items[i].SubItems[1].Text.Remove(0, 4).Remove(2);
                    string two2 = listView2.Items[i].SubItems[1].Text.Remove(0, 4).Remove(0, 2);
                    num += int.Parse(two2 + one1, NumberStyles.HexNumber);
                }
                List<ListViewItem> l = new List<ListViewItem>();
                string one11 = listView2.Items[int.Parse(two + one, NumberStyles.HexNumber)].SubItems[1].Text.Remove(0, 4).Remove(2);
                string two22 = listView2.Items[int.Parse(two + one, NumberStyles.HexNumber)].SubItems[1].Text.Remove(0, 4).Remove(0, 2);
                for (int i = 0; i < int.Parse(two22 + one11, NumberStyles.HexNumber); i++)
                {
                    l.Add(listView3.Items[num + i]);
                }
                Form f = new nsbmd_came(path_.Replace(Path.GetFileName(path_), "course_model.nsbmd"), listView19.SelectedItems[0], l.ToArray());
                f.Show(this);
            }
        }

        private void toolStripButton20_Click(object sender, EventArgs e)
        {
            Clipboard.SetData("NKM:OBJI", m.OBJI.Items[listView1.SelectedIndices[0]]);
        }

        private void toolStripButton21_Click(object sender, EventArgs e)
        {
            if (Clipboard.ContainsData("NKM:OBJI"))
            {
                OBJi l = (OBJi)Clipboard.GetData("NKM:OBJI");
                m.OBJI.Items.Add(l);
                ListViewItem n = new ListViewItem((listView1.Items.Count + 1).ToString());
                n.SubItems.Add(l.TransX.ToString());
                n.SubItems.Add(l.TransY.ToString());
                n.SubItems.Add(l.TransZ.ToString());
                n.SubItems.Add(l.RotX.ToString());
                n.SubItems.Add(l.RotY.ToString());
                n.SubItems.Add(l.RotZ.ToString());
                n.SubItems.Add(l.ScaleX.ToString());
                n.SubItems.Add(l.ScaleY.ToString());
                n.SubItems.Add(l.ScaleZ.ToString());
                n.SubItems.Add(System.BitConverter.ToString(l.ObjectID).Replace("-", "") + System.BitConverter.ToString(l.RouteID).Replace("-", ""));
                n.SubItems.Add(System.BitConverter.ToString(l.Setting1).Replace("-", ""));
                n.SubItems.Add(System.BitConverter.ToString(l.Setting2).Replace("-", ""));
                n.SubItems.Add(System.BitConverter.ToString(l.Setting3).Replace("-", ""));
                n.SubItems.Add(System.BitConverter.ToString(l.Setting4).Replace("-", ""));
                n.SubItems.Add(System.BitConverter.ToString(l.Setting5).Replace("-", ""));
                listView1.Items.Add(n);
                //chart1.Series[0].Points[listView1.SelectedIndices[0]].XValue = Convert.ToDouble(item.SubItems[1].Text);
                //chart1.Series[0].Points[listView1.SelectedIndices[0]].YValues[0] = Convert.ToDouble(item.SubItems[3].Text);
                if (Properties.Resources.ResourceManager.GetObject("OBJ_" + BitConverter.ToString(m.OBJI.Items[listView1.SelectedIndices[0]].ObjectID).Replace("-", "") + ((m.OBJI.Items[listView1.SelectedIndices[0]].ObjectID[0] == 0x6D && m.OBJI.Items[listView1.SelectedIndices[0]].ObjectID[1] == 0x00) == false ? "" : "-" + BitConverter.ToInt32(m.OBJI.Items[listView1.SelectedIndices[0]].Setting3.Reverse().ToArray(), 0))) != null)
                {
                    nkmEditorControl1.OBJI.Add( l.TransX,l.TransY,l.TransZ,l.RotY, (Bitmap)Properties.Resources.ResourceManager.GetObject("OBJ_" + BitConverter.ToString(l.ObjectID).Replace("-", "") + ((l.ObjectID[0] == 0x6D &&l.ObjectID[1] == 0x00) == false ? "" : "-" + BitConverter.ToInt32(l.Setting3.Reverse().ToArray(), 0))));
                }
                else
                {
                    //chart1.Series[0].Points[j].MarkerColor = Color.Red;
                    //nkmEditorControl1.OBJI.Add(m.OBJI.Items[j].TransX, m.OBJI.Items[j].TransY, m.OBJI.Items[j].TransZ, m.OBJI.Items[j].RotY);
                    //nkmEditorControl1.OBJI[listView1.SelectedIndices[0]].MarkerImage = null;
                    nkmEditorControl1.OBJI.Add(l.TransX, l.TransY, l.TransZ, l.RotY);
                }
                //listView1.Items.Add(l);
                //chart1.Series[0].Points.AddXY(Convert.ToDouble(l.SubItems[1].Text), Convert.ToDouble(l.SubItems[3].Text));
            }
        }
        int lastktps = -1;
        private void listView5_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lastktps != -1)
            {
                m.KTPS.Items[lastktps].TransX = (propertyGrid5.SelectedObject as KTPSObject).X;
                m.KTPS.Items[lastktps].TransY = (propertyGrid5.SelectedObject as KTPSObject).Y;
                m.KTPS.Items[lastktps].TransZ = (propertyGrid5.SelectedObject as KTPSObject).Z;
                m.KTPS.Items[lastktps].RotateX = (propertyGrid5.SelectedObject as KTPSObject).Xrot;
                m.KTPS.Items[lastktps].RotateY = (propertyGrid5.SelectedObject as KTPSObject).Yrot;
                m.KTPS.Items[lastktps].RotateZ = (propertyGrid5.SelectedObject as KTPSObject).Zrot;
                listView5.Items[lastktps].SubItems[1].Text = m.KTPS.Items[lastktps].TransX.ToString();
                listView5.Items[lastktps].SubItems[2].Text = m.KTPS.Items[lastktps].TransY.ToString();
                listView5.Items[lastktps].SubItems[3].Text = m.KTPS.Items[lastktps].TransZ.ToString();
                listView5.Items[lastktps].SubItems[4].Text = m.KTPS.Items[lastktps].RotateX.ToString();
                listView5.Items[lastktps].SubItems[5].Text = m.KTPS.Items[lastktps].RotateY.ToString();
                listView5.Items[lastktps].SubItems[6].Text = m.KTPS.Items[lastktps].RotateZ.ToString();
                nkmEditorControl1.KTPS[lastktps].X = m.KTPS.Items[lastktps].TransX;
                nkmEditorControl1.KTPS[lastktps].Y = m.KTPS.Items[lastktps].TransY;
                nkmEditorControl1.KTPS[lastktps].Z = m.KTPS.Items[lastktps].TransZ;
            }
            if (listView5.SelectedIndices.Count == 0)
            {
                toolStripButton4.Enabled = false;
                toolStripButton5.Enabled = false;
                toolStripButton22.Enabled = false;
                toolStripButton23.Enabled = false;
                propertyGrid5.SelectedObject = null;
                lastktps = -1;
            }
            else
            {
                toolStripButton4.Enabled = true;
                toolStripButton5.Enabled = true;
                toolStripButton22.Enabled = true;
                toolStripButton23.Enabled = true;
                KTPSObject oo = new KTPSObject();
                oo.X = m.KTPS.Items[listView5.SelectedIndices[0]].TransX;
                oo.Y = m.KTPS.Items[listView5.SelectedIndices[0]].TransY;
                oo.Z = m.KTPS.Items[listView5.SelectedIndices[0]].TransZ;
                oo.Xrot = m.KTPS.Items[listView5.SelectedIndices[0]].RotateX;
                oo.Yrot = m.KTPS.Items[listView5.SelectedIndices[0]].RotateY;
                oo.Zrot = m.KTPS.Items[listView5.SelectedIndices[0]].RotateZ;
                propertyGrid5.SelectedObject = oo;
                lastktps = listView5.SelectedIndices[0];
            }
        }
        int lastktp2 = -1;
        private void listView7_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lastktp2 != -1)
            {
                m.KTP2.Items[lastktp2].TransX = (propertyGrid7.SelectedObject as KTPSObject).X;
                m.KTP2.Items[lastktp2].TransY = (propertyGrid7.SelectedObject as KTPSObject).Y;
                m.KTP2.Items[lastktp2].TransZ = (propertyGrid7.SelectedObject as KTPSObject).Z;
                m.KTP2.Items[lastktp2].RotateX = (propertyGrid7.SelectedObject as KTPSObject).Xrot;
                m.KTP2.Items[lastktp2].RotateY = (propertyGrid7.SelectedObject as KTPSObject).Yrot;
                m.KTP2.Items[lastktp2].RotateZ = (propertyGrid7.SelectedObject as KTPSObject).Zrot;
                listView7.Items[lastktp2].SubItems[1].Text = m.KTP2.Items[lastktp2].TransX.ToString();
                listView7.Items[lastktp2].SubItems[2].Text = m.KTP2.Items[lastktp2].TransY.ToString();
                listView7.Items[lastktp2].SubItems[3].Text = m.KTP2.Items[lastktp2].TransZ.ToString();
                listView7.Items[lastktp2].SubItems[4].Text = m.KTP2.Items[lastktp2].RotateX.ToString();
                listView7.Items[lastktp2].SubItems[5].Text = m.KTP2.Items[lastktp2].RotateY.ToString();
                listView7.Items[lastktp2].SubItems[6].Text = m.KTP2.Items[lastktp2].RotateZ.ToString();
                nkmEditorControl1.KTP2[lastktp2].X = m.KTP2.Items[lastktp2].TransX;
                nkmEditorControl1.KTP2[lastktp2].Y = m.KTP2.Items[lastktp2].TransY;
                nkmEditorControl1.KTP2[lastktp2].Z = m.KTP2.Items[lastktp2].TransZ;
            }
            if (listView7.SelectedIndices.Count == 0)
            {
                propertyGrid7.SelectedObject = null;
                lastktp2 = -1;
            }
            else
            {
                KTPSObject oo = new KTPSObject();
                oo.X = m.KTP2.Items[listView7.SelectedIndices[0]].TransX;
                oo.Y = m.KTP2.Items[listView7.SelectedIndices[0]].TransY;
                oo.Z = m.KTP2.Items[listView7.SelectedIndices[0]].TransZ;
                oo.Xrot = m.KTP2.Items[listView7.SelectedIndices[0]].RotateX;
                oo.Yrot = m.KTP2.Items[listView7.SelectedIndices[0]].RotateY;
                oo.Zrot = m.KTP2.Items[listView7.SelectedIndices[0]].RotateZ;
                propertyGrid7.SelectedObject = oo;
                lastktp2 = listView7.SelectedIndices[0];
            }
        }
        int lastktpc = -1;
        private void listView8_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lastktpc != -1)
            {
                m.KTPC.Items[lastktpc].TransX = (propertyGrid8.SelectedObject as KTPSObject).X;
                m.KTPC.Items[lastktpc].TransY = (propertyGrid8.SelectedObject as KTPSObject).Y;
                m.KTPC.Items[lastktpc].TransZ = (propertyGrid8.SelectedObject as KTPSObject).Z;
                m.KTPC.Items[lastktpc].RotateX = (propertyGrid8.SelectedObject as KTPSObject).Xrot;
                m.KTPC.Items[lastktpc].RotateY = (propertyGrid8.SelectedObject as KTPSObject).Yrot;
                m.KTPC.Items[lastktpc].RotateZ = (propertyGrid8.SelectedObject as KTPSObject).Zrot;
                listView8.Items[lastktpc].SubItems[1].Text = m.KTPC.Items[lastktpc].TransX.ToString();
                listView8.Items[lastktpc].SubItems[2].Text = m.KTPC.Items[lastktpc].TransY.ToString();
                listView8.Items[lastktpc].SubItems[3].Text = m.KTPC.Items[lastktpc].TransZ.ToString();
                listView8.Items[lastktpc].SubItems[4].Text = m.KTPC.Items[lastktpc].RotateX.ToString();
                listView8.Items[lastktpc].SubItems[5].Text = m.KTPC.Items[lastktpc].RotateY.ToString();
                listView8.Items[lastktpc].SubItems[6].Text = m.KTPC.Items[lastktpc].RotateZ.ToString();
                nkmEditorControl1.KTPC[lastktpc].X = m.KTPC.Items[lastktpc].TransX;
                nkmEditorControl1.KTPC[lastktpc].Y = m.KTPC.Items[lastktpc].TransY;
                nkmEditorControl1.KTPC[lastktpc].Z = m.KTPC.Items[lastktpc].TransZ;
            }
            if (listView8.SelectedIndices.Count == 0)
            {
                propertyGrid8.SelectedObject = null;
                lastktpc = -1;
            }
            else
            {
                KTPSObject oo = new KTPSObject();
                oo.X = m.KTPC.Items[listView8.SelectedIndices[0]].TransX;
                oo.Y = m.KTPC.Items[listView8.SelectedIndices[0]].TransY;
                oo.Z = m.KTPC.Items[listView8.SelectedIndices[0]].TransZ;
                oo.Xrot = m.KTPC.Items[listView8.SelectedIndices[0]].RotateX;
                oo.Yrot = m.KTPC.Items[listView8.SelectedIndices[0]].RotateY;
                oo.Zrot = m.KTPC.Items[listView8.SelectedIndices[0]].RotateZ;
                propertyGrid8.SelectedObject = oo;
                lastktpc = listView8.SelectedIndices[0];
            }
        }
        private void toolStripButton23_Click(object sender, EventArgs e)
        {
            if (File.Exists(path_.Replace(Path.GetFileName(path_), "course_model.nsbmd")))
            {
                nsbmd b = new nsbmd(File.ReadAllBytes(path_.Replace(Path.GetFileName(path_), "course_model.nsbmd")));
                b.Show(this);
                b.Shown += new EventHandler(b_Shown);
            }
        }

        void b_Shown(object sender, EventArgs e)
        {
            nsbmd b = (nsbmd)sender;
            b.lookAt(Convert.ToDouble(listView5.SelectedItems[0].SubItems[1].Text), Convert.ToDouble(listView5.SelectedItems[0].SubItems[2].Text), Convert.ToDouble(listView5.SelectedItems[0].SubItems[3].Text));
        }

        private void toolStripButton17_Click(object sender, EventArgs e)
        {
            if (listView3.SelectedIndices.Count != 0 && listView3.SelectedItems[0].Index != 0)
            {
                POIt d = m.POIT.Items[listView3.SelectedIndices[0]];
                m.POIT.Items.RemoveAt(listView3.SelectedIndices[0]);
                m.POIT.Items.Insert(listView3.SelectedIndices[0] - 1, d);
                MKDS_Course_Editor.NKM.NkmPoitPoint p = nkmEditorControl1.POIT[listView3.SelectedIndices[0]];
                nkmEditorControl1.POIT.RemoveAt(listView3.SelectedIndices[0]);
                nkmEditorControl1.POIT.Insert(listView3.SelectedIndices[0] - 1, p);
                ListViewItem it = listView3.SelectedItems[0];
                int index = listView3.SelectedIndices[0];
                listView3.Items.RemoveAt(listView3.SelectedIndices[0]);
                listView3.Items.Insert(index - 1, it);
            }
        }

        private void toolStripButton18_Click(object sender, EventArgs e)
        {
            if (listView3.SelectedIndices.Count != 0 && listView3.SelectedItems[0].Index != listView3.Items.Count - 1)
            {
                POIt d = m.POIT.Items[listView3.SelectedIndices[0]];
                m.POIT.Items.RemoveAt(listView3.SelectedIndices[0]);
                m.POIT.Items.Insert(listView3.SelectedIndices[0] + 1, d);
                MKDS_Course_Editor.NKM.NkmPoitPoint p = nkmEditorControl1.POIT[listView3.SelectedIndices[0]];
                nkmEditorControl1.POIT.RemoveAt(listView3.SelectedIndices[0]);
                nkmEditorControl1.POIT.Insert(listView3.SelectedIndices[0] + 1, p);
                ListViewItem it = listView3.SelectedItems[0];
                int index = listView3.SelectedIndices[0];
                listView3.Items.RemoveAt(listView3.SelectedIndices[0]);
                listView3.Items.Insert(index + 1, it);
            }
        }

        private void nkmEditorControl1_MouseMove(object sender, MouseEventArgs e)
        {
        }

        private void nkmEditorControl1_Click(object sender, EventArgs e)
        {

        }

        private void nkmEditorControl1_PointerLocationChanged(object sender, EventArgs e)
        {
            toolStripLabel1.Text = nkmEditorControl1.locationX.ToString();
            toolStripLabel2.Text = nkmEditorControl1.locationY.ToString();
        }

        private void nkmEditorControl1_MouseUp(object sender, MouseEventArgs e)
        {

        }

        private void nkmEditorControl1_PointerClicked(object sender, EventArgs e)
        {
            toolStripLabel3.Text = nkmEditorControl1.locationX.ToString();
            toolStripLabel4.Text = nkmEditorControl1.locationY.ToString();
        }

        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            nkmEditorControl1.Invalidate();
        }

        private void toolStripSplitButton1_DropDownClosed(object sender, EventArgs e)
        {
            nkmEditorControl1.Invalidate();
        }

        private void toolStripSplitButton1_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            nkmEditorControl1.Invalidate();
        }

        

        

    }
    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
    public static class ListViewExtensions { [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]    private struct LVCOLUMN { public Int32 mask; public Int32 cx;        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string pszText; public IntPtr hbm; public Int32 cchTextMax; public Int32 fmt; public Int32 iSubItem; public Int32 iImage; public Int32 iOrder;    } private const Int32 HDI_FORMAT = 0x4; private const Int32 HDF_SORTUP = 0x400; private const Int32 HDF_SORTDOWN = 0x200; private const Int32 LVM_GETHEADER = 0x101f; private const Int32 HDM_GETITEM = 0x120b; private const Int32 HDM_SETITEM = 0x120c;    [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);    [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage")] private static extern IntPtr SendMessageLVCOLUMN(IntPtr hWnd, Int32 Msg, IntPtr wParam, ref LVCOLUMN lPLVCOLUMN); public static void SetSortIcon(this System.Windows.Forms.ListView ListViewControl, int ColumnIndex, System.Windows.Forms.SortOrder Order) { IntPtr ColumnHeader = SendMessage(ListViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero); for (int ColumnNumber = 0; ColumnNumber <= ListViewControl.Columns.Count - 1; ColumnNumber++) { IntPtr ColumnPtr = new IntPtr(ColumnNumber); LVCOLUMN lvColumn = new LVCOLUMN(); lvColumn.mask = HDI_FORMAT; SendMessageLVCOLUMN(ColumnHeader, HDM_GETITEM, ColumnPtr, ref lvColumn); if (!(Order == System.Windows.Forms.SortOrder.None) && ColumnNumber == ColumnIndex) { switch (Order) { case System.Windows.Forms.SortOrder.Ascending:                                        lvColumn.fmt &= ~HDF_SORTDOWN; lvColumn.fmt |= HDF_SORTUP; break; case System.Windows.Forms.SortOrder.Descending:                                        lvColumn.fmt &= ~HDF_SORTUP; lvColumn.fmt |= HDF_SORTDOWN; break; } } else { lvColumn.fmt &= ~HDF_SORTDOWN & ~HDF_SORTUP; } SendMessageLVCOLUMN(ColumnHeader, HDM_SETITEM, ColumnPtr, ref lvColumn); } } }
}
